我正在处理xml文件,有时会有 “I帧” 和 “脚本” 标签我需要离开,在我甚至'xml-parse-it'之前
我正在尝试一些正则表达式,但我弄错了! :(
测试字符串:
$teststring = 'p><iframe src="http://www.facebook.com/plugins/like.php?href=abcdef&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=dark&amp;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--> '@<iframe [^<]<.*?<\/iframe>@i',
);
$Replace = array(
'',
chr( 162 ),
chr( 163 ),
chr( 169 ),
chr( 174 ),
'chr()',
'',
);
//expecting <p></p>
$data = preg_replace( $Rules, $Replace, $teststring);
echo $data;
答案 0 :(得分:1)
试试这个
'@<iframe(?:(?!>).)*>.*?<\/iframe>@i'