2012-02-15 34 views
0

我處理XML文件,有時也有 「I幀」 和 「腳本」 標籤我要出去,我連「XML的前解析它'PHP條I幀和腳本標籤(無ヶ輛())

我正在嘗試一些正則表達式,但我得到它錯了! :(

測試字符串:

 $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; 

回答

1

只是嘗試這種

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

真棒:)謝謝! – user914584 2012-02-15 09:32:38

+0

非常棒....你是爐排男人。 :) – 2017-03-28 06:03:23

+0

非常感謝.... :) @lake – 2017-03-28 06:03:45