doudu3961 2014-10-07 06:11
浏览 35
已采纳

如何在PHP中正则表达式字符串[关闭]

I have the string that is the html code and i want to get some tag from this html. Tag like below:

    <td width="33%" align="left" class="MID">
    <a href="ShowDOTCoByState.cfm?STATE=US&PHY_ST=IA">IOWA</a>
    </td>

How can i get tags using regex?

  • 写回答

2条回答 默认 最新

  • dongzhuo7291 2014-10-07 06:17
    关注

    better use this :

    <?php
    $html='<td width="33%" align="left" class="MID"><a href="ShowDOTCoByState.cfm?STATE=US&amp;PHY_ST=IA">IOWA</a></td>" id="blabah" >help</a>';
    libxml_use_internal_errors(true);
    $dom = new DOMDocument;
    $dom->loadHTML($html);
    echo $dom->getElementsByTagName('a')->item(0)->nodeValue;
    

    this will get the value of the text written for link.

    demo here : https://eval.in/202356

    or if you are so fond on using regex :

    <td.*?class="MID"[^>]*[\s\S]*?<\/td>
    

    demo here : http://regex101.com/r/aS9pV1/1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容