Re: Parsing HTML href-Attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 15, 2009 at 5:13 PM, Edmund Hertle
<edmund.hertle@xxxxxxxxxxxxxxx> 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
>

You could also use DOM for this.

http://us2.php.net/manual/en/domdocument.getelementsbytagname.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux