homepage Welcome to WebmasterWorld Guest from 54.198.224.121
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Regular Expressions help
Need to extract links and anchor text from HTML
robster124




msg:1266984
 10:27 pm on Jul 16, 2005 (gmt 0)

OK,

I thought I was proficcient in PHP until I came across regex.

In short, I have tonnes of HTML which I need to extract "href" links from complete with anchor text (if applicable).

I need a preg_match_all function regex that can give me an array of 1) The entire HTML <A> tag (e.g. <a href='http:\\www.example.com'>Example link</a> 2) Just the URL (full URL, not just domain) and 3) Anchor text

I've only seen a few suggested expressions, all of which havent worked on searches.

The regex needs to be able to take care of <a> tag anomalies where the <a is separated from the 'href' through 'onclick's etc.

Thanks

 

willybfriendly




msg:1266985
 10:53 pm on Jul 16, 2005 (gmt 0)

This is the place to start

[etext.lib.virginia.edu...]

WBF

robster124




msg:1266986
 9:14 am on Jul 17, 2005 (gmt 0)

Unfortunately, I've already tried teaching myself regex but have got nowhere with this particular task. Any help is appreciated.

arran




msg:1266987
 9:35 am on Jul 17, 2005 (gmt 0)

robster,

[php-html.sourceforge.net ] could do the job.

arran.

robster124




msg:1266988
 9:46 pm on Jul 17, 2005 (gmt 0)

Thx

Ill give it a go

ivanw




msg:1266989
 3:58 pm on Jul 18, 2005 (gmt 0)

Do a Google on "Regexbuddy". The accompanying site is the best introduction to regex I've seen yet.

cheers,
Ivan

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved