dongshen7407 2013-04-27 16:18
浏览 15
已采纳

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

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.

  • 写回答

2条回答 默认 最新

  • dopt85756 2013-04-27 21:35
    关注

    You must first extract the line and after find the numbers:

    if (preg_match('~\["listidname",\[],\{"list":(?:[[,]"\d++")++]},\d++]~', $html, $match)) {
        preg_match_all('~"\K\d++~', $match[0] ,$result);
        print_r($result);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog