Main Content

PHP Regular expression to extrtact link and text

Archive - Originally posted on "The Horse's Mouth" - 2007-01-31 05:57:59 - Graham Ellis

How many special characters can you realistically use in a regular expression without a single space, letter or digit? Here's one I wrote yesterday.

eregi('href="([^"]+)"[^>]*>([^<]+)',$line,$parts);

Far fetched example? No - it's part of a link checker that picks out a URL and the text that appears on the link ...