php preg_match_all用括号括起来的数字 [英] php preg_match_all numbers in parentheses

查看:469
本文介绍了php preg_match_all用括号括起来的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载远程网站并获取括号内的所有数字.但是最终发生的是它只匹配最后一个值.

I am trying to load a remote website and get all numbers that are inside of parentheses. But what ends up happening is it only matches the last value.

我的正则表达式错了吗?我使用的标志正确吗?

Is my regex wrong? Am I using the correct flags?

我在第二个$ html变量中添加了匹配示例.

I have added the example of what it should match on in the second $html variable.

    //$html = file_get_contents("http://example.com/test.html");

    $html = "(1234) (12) (1)  \r\n  (1346326)";
    preg_match_all("^[(\d)]+$^", $html, $matches, PREG_PATTERN_ORDER);
    print_r($matches);
    echo "<br>";
    foreach ($matches as $val) {
        echo "matched: " . $val[0] . "\n";

    }

谢谢.

推荐答案

怎么样:

preg_match_all("/\((\d+)\)/", $html, $matches, PREG_PATTERN_ORDER); 
print_r($matches[1]);

这篇关于php preg_match_all用括号括起来的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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