I have a PHP page which looks through some HTML for links and replaces them with links to a local PHP page; the problem is finding image links. I currently use this code:
$data = preg_replace('|(<a\s*[^>]*href=[\'"]?)|','\1newjs.php?url=', $data);
Which matches things like
<a href="http://google.com">Google</a>
and will replace them with
<a href="newjs.php?url=http://google.com">Google</a>
I am looking to do a similar things with image files (jpg, gif, png) and replace something like:
<a href="http://google.com/hello.png">Image</a>
With this:
<a href="newjs.php?url=http://google.com/hello.png&image=1">Image</a>
Note the '&image=1' in the new URL. Is it possible for me to do this using PHP, preferably with regular expressions?