Jump to content

downloading content from url in array


DaGeek247

Recommended Posts

Alrighty, I have posted about this before, but for a very different question. So different, i figured it merited a different post. anyways...

 

I have a php script that downloads a webpages html code, then shows that code as its own on another server. I got it to work great, but it does not download/show the images and css. Using <base href> works great for the links, but the images are an issue, along with the css.

 

Here's what I have got so far: (any scripts or other stuff is greatly appreciated)

<?php
//download the webpage
$contents = file_get_contents($url);
//we have downloaded the html from the page,
//but not the external files such as css, and images
//so now we add the images and css
//start by splitting it into an easy to manage array
$contentchunks = explode("/n", $contents);

//mess with the html we downloaded
foreach($contentchunks as $varname => $varval){ //varval is the single line of html
  //go through every line of the html code and replace it to my heart's content
  if(stristr($varval, 'src=') === TRUE) { //check to see if has what im looking for
    //get the url to download
    
    //download and insert the image
  }
}

//put the modified array back together
$contents = implode("/n", $contentchunks);
//view the webpage
echo $contents;
?>

I have a demonstration of what it does over at http://dageek247.tk/viewit/

Link to comment
https://forums.phpfreaks.com/topic/256352-downloading-content-from-url-in-array/
Share on other sites

Andy-H, im not sure if your link was sarcastic, or serious. either way, I had no idea what i was doing had been done before, so thanks. I think i got it now. im using my own modified version of http://www.doncaprio.com/2011/01/how-to-create-free-php-proxy-site.html And its working a lot better than what i ever thought i could acheive with my resources / knowledge. *solved*

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.