【问题标题】:php strip iframes and scripts tags (no htmlentities())php 去除 iframe 和脚本标签(没有 htmlentities())
【发布时间】:2012-02-15 08:45:44
【问题描述】:

我正在处理一个 xml 文件,有时有 “iframe” 和 “脚本” 在我什至'xml-parse-it'之前我需要离开的标签

我正在尝试一些正则表达式,但我弄错了! :(

测试字符串:

      $teststring = 'p><iframe src="http://www.facebook.com/plugins/like.php?href=abcdef&layout=standard&show_faces=false&width=450&action=like&colorscheme=dark&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowtransparency="true"></iframe></p>';

 //todo clean this up// found this function on net. //more legacy stufff
    $Rules = array(
         '@<script[^>]*?>.*?</script>@si', // Strip out javascript                
        '@&(cent|#162);@i', //   Cent 
        '@&(pound|#163);@i', //   Pound
        '@&(copy|#169);@i', //   Copyright
        '@&(reg|#174);@i', //   Registered
        '@&#(d+);@e', // Evaluate as php
---> PROBLEM--> '@&lt;iframe [^&lt;]&lt;.*?&lt;\/iframe&gt;@i',

    );

    $Replace = array(
         '',
        chr( 162 ),
        chr( 163 ),
        chr( 169 ),
        chr( 174 ),
        'chr()',
        '',

    );
        //expecting <p></p>
    $data = preg_replace( $Rules, $Replace, $teststring);


            echo $data;

【问题讨论】:

    标签: php regex iframe strip


    【解决方案1】:

    试试这个

    '@&lt;iframe(?:(?!&gt;).)*&gt;.*?&lt;\/iframe&gt;@i'
    

    【讨论】:

      猜你喜欢
      • 2011-04-21
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      • 2019-07-30
      • 2014-12-27
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      相关资源
      最近更新 更多