Re: Parsing HTML href-Attribute
| From: | Micah Gersten | Date: | Mon, 19 Jan 2009 02:50:10 +0000 |
| Subject: | Re: Parsing HTML href-Attribute | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-286638@lists.php.net to get a copy of this message | ||
Depending on the goal, using the base tag in the head section might help:
http://www.w3.org/TR/REC-html40/struct/links.html#h-12.4
Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com
Edmund Hertle wrote:
> Hey,
> I want to "parse" a href-attribute in a given String to check if there is a
> relative link and then adding an absolute path.
> Example:
> $string = '<a class="sample" [...additional attributes...]
> href="/foo/bar.php" >';
>
> I tried using regular expressions but my knowledge of RegEx is very limited.
> Things to consider:
> - $string could be quite long but my concern are only those href attributes
> (so working with explode() would be not very handy)
> - Should also work if href= is not using quotes or using single quotes
> - link could already be an absolute path, so just searching for href= and
> then inserting absolute path could mess up the link
>
> Any ideas? Or can someone create a RegEx to use?
>
> Thanks
>
>