我正在用curl解析一些html代码。一些站点html源代码,如:
<div id="content">
some words
</div>
<?
$box_social['dimensioni']="80";
$box_vota=array();
$box_vota["novideo"]='';
$box_vota["nofoto"]='';
$box_vota["id_articolo"]='1003691';
include($_SERVER['DOCUMENT_ROOT']."/incs/box_social.php");
?>
<div id="footer">
some words
</div>如何从html源码中删除php短标签?我需要
<div id="content">
some words
</div>
<div id="footer">
some words
</div>我使用的是preg_replace('/<\?(.*?)\?>/','',$html);,但php的短标记部分仍然存在。
发布于 2013-02-05 01:09:42
此正则表达式与您的大小写匹配:
$html = htmlspecialchars(preg_replace('/<\?([\w\W]*)\?>/','',$html));
$html = htmlspecialchars(preg_replace('/<\?(.*)\?>/s','',$html));如果有多个PHP代码块,也会匹配:
$html = htmlspecialchars(preg_replace('/<\?([^\?>]*)\?>/','',$html));来自PHP.NET
s (PCRE_DOTALL)如果设置了此修饰符,则模式中的点元字符将匹配所有字符,包括换行符。如果没有它,换行符将被排除。这个修饰符等同于Perl的/s修饰符。负的类,如^a,总是匹配换行符,与这个修饰符的设置无关。
https://stackoverflow.com/questions/14691575
复制相似问题