Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: preg_match() not correct

I have the following string:

<w:pPr>
    <w:spacing w:line="240" w:lineRule="exact"/>
    <w:ind w:left="1890" w:firstLine="360"/>
    <w:rPr>
        <w:b/>
        <w:color w:val="00000A"/>
        <w:sz w:val="24"/>
    </w:rPr>
</w:pPr>

and I am trying to parse the "w:sz w:val" value using preg_match().

So far, I've tried:

preg_match('/<w:sz w:val="(\d)"/', $p, $fonts);

but this has not worked, and I'm unsure why?

Any Ideas?

Thank you in advance!

like image 534
jldavis76 Avatar asked Jul 25 '26 21:07

jldavis76


1 Answers

You were trying to capture only single-digit numbers. Try adding a + to make "one or more".

preg_match('/<w:sz w:val="(\d+)"/', $p, $fonts);

I prefer [0-9]+ for easier reading, and because it avoids the potentially funny need to double-up on \ symbols.

preg_match('/<w:sz w:val="([0-9]+)"/', $p, $fonts);
like image 116
starlocke Avatar answered Jul 27 '26 12:07

starlocke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!