papaface Posted December 5, 2010 Share Posted December 5, 2010 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> I am trying to retrieve the href in this line using regex: <a href="http://www.domain.com/asp-tutorials" class="catTitle"> 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); 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? Quote Link to comment https://forums.phpfreaks.com/topic/220722-retrieving-info-using-regex-problem/ Share on other sites More sharing options...
.josh Posted December 5, 2010 Share Posted December 5, 2010 All by itself it works...though if all you want is the href="..." and all the relevant anchor tags have the class="catTitle" in it, you don't really need all that extra pattern matching surrounding it. But anyways, as mentioned, all by itself it works. I took the example html and code you have and put it on a test page and I get Array ( [0] => Array ( [0] => ASP Tutorials ASP Tutorials [1] => http://www.domain.com/asp-tutorials ) ) so if it's not working for you then... I would check to make sure that your $file variable is getting the content to regex in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/220722-retrieving-info-using-regex-problem/#findComment-1143240 Share on other sites More sharing options...
papaface Posted December 5, 2010 Author Share Posted December 5, 2010 Thanks. I realised it was outputting, but I just couldnt see it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/220722-retrieving-info-using-regex-problem/#findComment-1143258 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.