1

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 の短いタグの部分がまだ残っています。

4

1 に答える 1

1

この正規表現はあなたのケースと一致します:

$html = htmlspecialchars(preg_replace('/<\?([\w\W]*)\?>/','',$html));
$html = htmlspecialchars(preg_replace('/<\?(.*)\?>/s','',$html));

これは、PHP のブロックが複数ある場合にも一致します。

$html = htmlspecialchars(preg_replace('/<\?([^\?>]*)\?>/','',$html));

PHP.NETから

■ (PCRE_DOTALL) この修飾子が設定されている場合、パターン内のドット メタ文字は、改行を含むすべての文字と一致します。それがない場合、改行は除外されます。この修飾子は、Perl の /s 修飾子と同等です。[^a] などの否定的なクラスは、この修飾子の設定に関係なく、常に改行文字と一致します。

于 2013-02-04T17:09:42.013 に答える