Alex Rivera | Logout

Grabbing the href attribute of an A element

Asked 2010-09-29T10:18:14.833
121

Trying to find the links on a page.

my regex is:

/<a\s[^>]*href=(\"\'??)([^\"\' >]*?)[^>]*>(.*)<\/a>/

but seems to fail at

<a title="this" href="that">what?</a>

How would I change my regex to deal with href not placed first in the a tag?

Edit
Report

1 Answer

4

The pattern you want to look for would be the link anchor pattern, like (something):

$regex_pattern = "/<a href=\"(.*)\">(.*)<\/a>/";
answered 2010-09-29T10:22:23.720

Your Answer