Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.