PHP:preg_match()不正确 [英] PHP: preg_match() not correct

查看:245
本文介绍了PHP:preg_match()不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串:

<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>

我正在尝试使用preg_match()解析 w:sz w:val值。

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?

有任何想法吗?

谢谢!

推荐答案

您试图仅捕获一位数字。尝试添加+以使一个或多个。

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);

我更喜欢[0-9] +以便于阅读,因为它避免了潜在的有趣需求

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);

这篇关于PHP:preg_match()不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆