0

I am trying to extract all the numbers from a page. The page looks like this:

....lots of html code ....
<script>
..some code...
["listidname",[],{"list":["123456","96326478664","12345678901234"]},12]
...more code....
</script>
...even more code...

The amount of numbers in the list can vary, also the 12 at the end is just a random number, so this can vary as well.

what I am trying to do is extract the 123456, 96326478664 and 12345678901234. However I am not really strong with php let alone regexes..

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

gives me the numbers, but also all the other numbers on the page...

Can anyone help me with this? Thank you.

4

2 回答 2

1

如果数字将在双引号中尝试

preg_match_all("/\"(\d+)\"/", $input, $output);
于 2013-04-27T16:25:22.093 回答
0

您必须先提取该行,然后找到数字:

if (preg_match('~\["listidname",\[],\{"list":(?:[[,]"\d++")++]},\d++]~', $html, $match)) {
    preg_match_all('~"\K\d++~', $match[0] ,$result);
    print_r($result);
}
于 2013-04-27T21:35:39.420 回答