[英]remove php short tags from html source
我正在解析一些帶有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短標記部分仍然存在。
此正則表達式符合您的情況:
$html = htmlspecialchars(preg_replace('/<\?([\w\W]*)\?>/','',$html));
$html = htmlspecialchars(preg_replace('/<\?(.*)\?>/s','',$html));
如果存在多個PHP塊,這也將匹配:
$html = htmlspecialchars(preg_replace('/<\?([^\?>]*)\?>/','',$html));
s(PCRE_DOTALL)如果設置了此修飾符,則模式中的點元字符將匹配所有字符,包括換行符。 沒有它,換行符將被排除。 此修飾符等效於Perl的/ s修飾符。 否定類(例如[^ a])始終與換行符匹配,而與該修飾符的設置無關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.