Abel Jojo
Abel Jojo

Reputation: 758

PHP preg_match results null

$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);

the above code results

0Array ( )

$search ie my subject is : -

<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>

i had tested it online and gets correct answer result 1. http://www.phpliveregex.com/p/xu and may other sites i failed to execute in my php file

Upvotes: 0

Views: 350

Answers (1)

Elias Van Ootegem
Elias Van Ootegem

Reputation: 76395

$search ie my subject is : -

<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>

No it isn't, it's &gt;div class=&#039;..., because you've called htmlentities, check the docs here.
Besides, parsing html like this would be easier with the aid of the DOMDocument object, IMHO

Upvotes: 1

Related Questions