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