Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用正则表达式获取数字_Php_Regex_Extraction - Fatal编程技术网

在php中使用正则表达式获取数字

在php中使用正则表达式获取数字,php,regex,extraction,Php,Regex,Extraction,我试图从一页中提取所有数字。 页面如下所示: ....lots of html code .... <script> ..some code... ["listidname",[],{"list":["123456","96326478664","12345678901234"]},12] ...more code.... </script> ...even more code... 给我数字,还有页面上的所有其他数字 有人能帮我吗? 谢谢。如果数字是双引号,请尝试 p

我试图从一页中提取所有数字。 页面如下所示:

....lots of html code ....
<script>
..some code...
["listidname",[],{"list":["123456","96326478664","12345678901234"]},12]
...more code....
</script>
...even more code...
给我数字,还有页面上的所有其他数字

有人能帮我吗?
谢谢。

如果数字是双引号,请尝试

preg_match_all("/\"(\d+)\"/", $input, $output);

您必须首先提取行,然后查找数字:

if (preg_match('~\["listidname",\[],\{"list":(?:[[,]"\d++")++]},\d++]~', $html, $match)) {
    preg_match_all('~"\K\d++~', $match[0] ,$result);
    print_r($result);
}

是否只希望数字用双引号括起来?使用
print\r(json\u decode($input))
这只是html文件中的一段代码。我宁愿使用正则表达式直接从他们的代码中获取它,除非你能告诉我一种从中提取json部分的方法…?谢谢!不过,我不得不将print_r($result)放在if语句的括号内。
if (preg_match('~\["listidname",\[],\{"list":(?:[[,]"\d++")++]},\d++]~', $html, $match)) {
    preg_match_all('~"\K\d++~', $match[0] ,$result);
    print_r($result);
}