I am fetching content from a website for parsing and displaying it's contents. When I display the contents, all of the images and links are broken.
Here's a bit of code to get the contents from a website into $buffer and then search and replace the contents with ParseContents() and empty the remains into $content
function GrabSite($url){
$fd = fopen ($url, "are");
while (!feof ($fd)) {
$buffer = fread($fd, 4096);
$content .= ParseContents($buffer);
}
fclose ($fd);
echo $content;
}
Because the site is stored in a variable on my domain, the whole src="..." and href="..." links become wrong.
So i need a regular expression, which searches for these tags and replaces them with correct links. I need to keep in mind that links will sometimes be encapsulated in ' or " or nothing at all.
I've been experimenting for a week with no luck.