dongtun1683 2014-11-11 16:12 采纳率: 0%
浏览 45
已采纳

php正则表达式无法在php中工作[preg_replace}

I am trying to remove the following html but my regex isn't working

<div class="vmargin"><div><iframe src="/test.php?u=N0Bhlant98C6MRj0D44HwJMuf5TdA%2F24oG9hQ2qqX6IR2IruUxVrrhLR4EpHQDvGtuHH4%2BLgJMBG6L5%2BTs6t6FfgCbo%3D&amp;b=5&amp;f=frame" style="width:718px;height:438px;border:0;margin:0;padding:0;" __idm_frm__="100"></iframe></div><div><a href="" class="report_video" data-video-id="732253" title="Report Video">Video Broken?</a></div></div>

I tried the following regex

preg_replace("@<div class=\"vmargin\".*?<\\/div>.*?<\\/div><\\/div>@s",'', $input); 

What's wrong with it

  • 写回答

2条回答 默认 最新

  • douchui7332 2014-11-11 16:17
    关注

    Do not use \\ because in your closing divs, there are no \ character. Try this:

    <div class=\"vmargin\".*?<\/div>.*?<\/div><\/div>
    

    So:

    $string = '<div class="vmargin"><div><iframe src="/test.php?u=N0Bhlant98C6MRj0D44HwJMuf5TdA%2F24oG9hQ2qqX6IR2IruUxVrrhLR4EpHQDvGtuHH4%2BLgJMBG6L5%2BTs6t6FfgCbo%3D&amp;b=5&amp;f=frame" style="width:718px;height:438px;border:0;margin:0;padding:0;" __idm_frm__="100"></iframe></div><div><a href="" class="report_video" data-video-id="732253" title="Report Video">Video Broken?</a></div></div>';
    $input = preg_replace("@<div class=\"vmargin\".*?<\/div>.*?<\/div><\/div>@s", '', $string);
    var_dump($input);
    

    Output: string '' (length=0)

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

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程