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>

我在网上对其进行了测试并得到了正确的答案结果 1. http://www.phpliveregex.com/p/xu 以及我未能在我的 php 文件中执行的其他网站

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 会更容易,恕我直言DOMDocument

于 2013-06-12T08:38:39.763 回答