I have used preg match to find in a page all img tags:

<(img)[^>]*?>

Can someone please tell me how i would check if it has a full url and if it does not replace it with a full url from a variable called $link2. I would also like to be able to process urls which have change directory such as: ../images/example.gif --> to http://example.com/images/example.gif using the http://example.com previously stored in $link2.

I have tried, without any luck:

if ($urlres = true) {
						
						for($i = 0, $size = sizeof($matches[0]); $i < $size; ++$i)
					{
					$imgurl =  preg_match_all('#http:\/\/#si', $matches[0][$i], $matches);
					if ($imgurl = true) {break;} else 
					preg_replace('#src="#si', '#src="$link2#', $matches[0][$i]);
					}
			}

Thanks

Recommended Answers

All 2 Replies

I don't know about the other stuff but I know for a fact your second code didn't work be cause if ($urlres = true) { should be if ($urlres == true) { instead.

Oh, and why are you using #?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.