for example i've got a string like this:
$html = '
<a href="test.html">test</a>
<a href="http://mydomain.com/test.html">test</a>
<a href="http://otherdomain.com/test.html">test</a>
<a href="someothertest/otherdir/hi.html">hi</a>
';
and i want to append the absolute url to all hrefs where no abolute domain is given.
$html = '
<a href="http://mydomain.com/test.html">test</a>
<a href="http://mydomain.com/test.html">test</a>
<a href="http://otherdomain.com/test.html">test</a>
<a href="http://mydomain.com/someothertest/otherdir/hi.html">hi</a>
';
whats the best way to do that? i guess something with RegEx, but my RegEx skills are ** ;)
thanks in advance!
The previous answer will cause problems with your first and fourth example because it fails to include a forward slash to separate the page from the page name. Admittedly this can be fixed by simply appending it to the $domain, but if you do that then href="/something.php" will end up with two.
Just to give an alternative Regex solution you could go with something like this...
However it is worth noting that with a link such as href="example.html" the link is relative to the current directory neither method shown so far will work correctly for relative links that aren't in the root directory. In order to provide a solution that is though more information would be required about where the information came from.
found a good way :
you can use
(?!http|mailto)
if you have also mailto links in your $html