I'm trying to create a program using PHP where I can load a full webpage and navigate the site while still staying in a different domain. The problem I'm having is that I can't load things like stylesheets and images because they are relative links. I need a way to make the relative links in to absolute links.
Right now I can get just plain HTML from the page using this handy bit of code:
echo file_get_contents('http://tumblr.com');
I can't use an iframe to display the webpage.
Your code should work, but you must set allow_url_fopen
to on
before running it.
echo file_get_contents('http://othersiteurl.com');
You may also use cURL. Example:
function get_data($url, $timeout = 5) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Slightly modified code from: https://davidwalsh.name/curl-download
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.