Hi I have the following HTML: <div class="categories"> <a href="http://www.domain.com/asp-tutorials" class="catTitle"> <img src="http://www.domain.com/img/29.jpg" alt="ASP Tutorials"></a> <a href="http://www.domain.com/asp-tutorials" class="floatLeft catTitle">ASP Tutorials</a><a href="http://www.domain.com/asp-tutorials/rss/categories.php?chid=29" title="RSS Feed for all ASP Tutorials!" class="rss"><img src="http://www.domain.com/images/rss_icon.gif" width="28" height="12" alt=""/></a> </div> Code (markup): I am trying to retrieve the href in this line using regex: <a href="http://www.domain.com/asp-tutorials" class="catTitle"> Code (markup): I have this: $expr = '/<div class="categories">.*?<a href="(.*?)" class="catTitle">.*?<img src=".*?" alt=".*?"><\/a>.*?<\/div>/s'; preg_match_all($expr,$file,$info,PREG_SET_ORDER); print_r($info); Code (markup): But it is returning no results. There are a few categories on the page which I'm trying to retrieve the links for. Anyone have any idea why?
Try this in a test file.php $page = '<div class="categories"> <a href="http://www.domain.com/asp-tutorials" class="catTitle"> <img src="http://www.domain.com/img/29.jpg" alt="ASP Tutorials"></a> <a href="http://www.domain.com/asp-tutorials" class="floatLeft catTitle">ASP Tutorials</a><a href="http://www.domain.com/asp-tutorials/rss/categories.php?chid=29" title="RSS Feed for all ASP Tutorials!" class="rss"><img src="http://www.domain.com/images/rss_icon.gif" width="28" height="12" alt=""/></a> </div>'; preg_match_all('#href="([^"]+)"#i',$page, $href); print_r($href); echo "<br /><br />"; echo $href[1][0]; echo "<br /><br />"; echo $href[1][1]; echo "<br /><br />"; echo $href[1][2]; echo "<br /><br />"; echo $href[1][3]; echo "<br /><br />"; echo $href[1][4]; PHP:
There are lots of div blocks on the same page with the same layout but contain info I don't want. It needs to specifically home in on "class="catTitle">"
Theres only 1 match for that ? preg_match_all('#href="([^"]*)" class="catTitle"#i',$page, $href); PHP: Do you need something different ?