php 剥离 iframe 和脚本标签(无 htmlentities())
我正在处理一个xml文件,有时会出现 “iframe” 和 “脚本” 我需要去掉标签,在我“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;
I'm processing a xml file and sometimes there are
"iframes"
and
"script"
tags i need to get out , before i even 'xml-parse-it'
I'm trying some regular expressions but i'm getting it wrong ! :(
test string:
$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--> '@<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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
Just Try this