Два простых способа распечатать содержимое (HTML) главной страницы google.com:
<code><?php
$content = file_get_contents("http://www.google.com/");
echo '<pre>'.htmlspecialchars($content).'
';
?>
Если этот метод не работает (из-за того, что обертки URL-адресов не включены, используйте второй метод ниже).
2) Использование cURL
:
<code><?php
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$content = file_get_contents_curl("http://www.google.com/");
echo '<pre>'.htmlspecialchars($content).'
';
?>