Jump to content

Retrieving info using regex problem


papaface

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/220722-retrieving-info-using-regex-problem/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.