I've run into a hard problem to deal with. I am replacing a-tags and img-tags to fit my suggestions like this. So far so good.
$search = array('|(<a\s*[^>]*href=[\'"]?)|', '|(<img\s*[^>]*src=[\'"]?)|');
$replace = array('\1proxy2.php?url=', '\1'.$url.'/');
$new_content = preg_replace($search, $replace, $content);
Now my problem is that there are links on pages that i fetch the content of that looks like this:
<a href="/test/page/">
and
<a href="http://google.se/test/">
And when after replacing these two links looks like this:
<a href="proxy2.php?url=/test/page/">
and
<a href="proxy2.php?url=http://google.se/test/">
The problem is for me is that i want to include a variable named $url before /test/page/ and only on that links that are like that, not those who was already http:// or https:// before.