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 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径