0
$pattern = '/^<div\sclass="yui3-u-2-3"><div\sid=left><h2\sclass="ehr">(.*?)<\/h2>/';
$subject = htmlentities($search, ENT_QUOTES, "UTF-8");
$arslt=preg_match( $pattern, $subject,$matches);
if($arslt==1)
echo 'delete';
 else
echo $arslt;
print_r($matches);

上記のコードの結果

0Array ( )

$search つまり、私の件名は : -

<div class="yui3-u-2-3"><div id=left><h2 class="ehr">Suggestions</h2><div class="post"><ul><li class="hindiresult">See the <a href="/help">help</a> to know how search results can be improved</li><li class="hindiresult">Ask in our <a href="/forums">forum</a></li><li class="hindiresult">Send us <a href="/contact">email</a></li></ul></div><h2 class="ehr">Definitions of Chaise</h2><h3>noun</h3><ol class="wnol"><li class="hindiresult">a long chair; for reclining</li><li class="hindiresult">a carriage consisting of two wheels and a calash top; drawn by a single horse</li></ol></div></div><div class="yui3-u-1-3"><div id="right"><div class="adbox"><script type="text/javascript"><!-- google_ad_client = "pub-7708924170316014";google_ad_slot="0743863500";google_ad_width=300;google_ad_height=250; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div></div></div>

私はそれをオンラインでテストし、正しい答え の結果を取得しました

4

1 に答える 1

1

$search つまり、私の件名は : -

<div class="yui3-u-2-3"><div id=left><h2 class="ehr">Suggestions</h2><div class="post"><ul><li class="hindiresult">See the <a href="/help">help</a> to know how search results can be improved</li><li class="hindiresult">Ask in our <a href="/forums">forum</a></li><li class="hindiresult">Send us <a href="/contact">email</a></li></ul></div><h2 class="ehr">Definitions of Chaise</h2><h3>noun</h3><ol class="wnol"><li class="hindiresult">a long chair; for reclining</li><li class="hindiresult">a carriage consisting of two wheels and a calash top; drawn by a single horse</li></ol></div></div><div class="yui3-u-1-3"><div id="right"><div class="adbox"><script type="text/javascript"><!-- google_ad_client = "pub-7708924170316014";google_ad_slot="0743863500";google_ad_width=300;google_ad_height=250; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div></div></div>

いいえ、そうではありません&gt;div class=&#039;...。電話をかけたので、こちらのドキュメントhtmlentitiesを確認してください。 その上、このようなhtmlの解析はオブジェクトの助けを借りて簡単になりますIMHO
DOMDocument

于 2013-06-12T08:38:39.763 に答える