duan00529 2015-11-21 04:40 采纳率: 100%
浏览 30

正则表达式,获取值结束标记

Hello this is my code:

<?php
require('/simple_html_dom.php');
$html = new simple_html_dom();
$html = file_get_html('proxys.html');

$items = array();
$re = "/<td class=\\\"t_ip\\\">\\s*((?:[0-9]{1,3}\\.){3}[0-9]{1,3})\\s*<\\/td>(?:.*?)*<td class=\"t_port\">(?:.*?)\\w+\\^\\w+\\^([0-9]{1,5})(?:.*?)<td class=\"t_type\">\\s*([0-9])(?:.*?)/"; 

        preg_match_all($re, $html, $matches, PREG_SET_ORDER);
        foreach ($matches as $val) {
        echo nl2br($val[1] . ':' . $val[2] . ' ' . $val[3] . "
");
        };

?>

proxys.html

<td class="t_ip">104.131.248.140</td><td class="t_port">           <script type="text/javascript">           //<![CDATA[             document.write(BigBlind^BigBlind^60088);           //]]>           </script>50088         </td><td class="t_type">     5         </td><td class="t_ip">79.101.32.14</td><td class="t_port">           <script type="text/javascript">           //<![CDATA[             document.write(Polymorth^Polymorth^1080);           //]]>           </script>45080         </td>

The problem is that the value is obtained "60088" of ****document.write(BigBlind^BigBlind^60088);****

104.131.248.140:    60088 5
79.101.32.14:       1080 4

and would like to get the value of < / script>50088

104.131.248.140:    50088 5
79.101.32.14:       45080 4

I'm lost with regular expression, Thank you for your help

  • 写回答

1条回答 默认 最新

  • douyin2962 2015-11-21 04:56
    关注

    You can try using DOMDocument like as

    $html = '<td class="t_ip">104.131.248.140</td><td class="t_port">           <script type="text/javascript">           //<![CDATA[             document.write(BigBlind^BigBlind^60088);           //]]>           </script>50088         </td><td class="t_type">     5         </td><td class="t_ip">79.101.32.14</td><td class="t_port">           <script type="text/javascript">           //<![CDATA[             document.write(Polymorth^Polymorth^1080);           //]]>           </script>45080         </td>';
    
    $dom = new DOMDocument;
    $dom->loadHTML($html);
    $root = $dom->documentElement;
    $tds = $root->getElementsByTagName("td");
    foreach($tds as $key => $value){
        echo $value->parentNode->textContent."<br>";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题