你可以使用Curl http://php.net/manual/en/book.curl.php请求从任何网站检索信息(xml/html/json/等)。
什么是卷曲? (简短回答)
PHP 有一个非常强大的调用库,专门用于安全地从远程站点获取数据。它被称为卷曲。
来源 :PHP、CURL,还有你! http://blog.unitedheroes.net/curl/
PHP 中的 Curl 函数示例
/* gets the data from a URL */
function get_data($url)
{
if(function_exists('curl_init')){
$ch = curl_init();
$timeout = 5;
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;
} else 'curl is not available, please install';
}
来源 :使用 PHP cURL 下载 URL 的内容 http://davidwalsh.name/download-urls-content-php-curl
或者,您可以执行当前正在执行的操作file_get_contents
但许多主机不允许这样做。 (沃尔什,2007)
Usage
<?php
$mydata = get_data('http://www.google.co.nz');
echo '<pre>';
print_r($mydata); //display the contents in $mydata as preformatted text
echo '</pre>';
?>
尝试使用其他网站进行测试,因为通常情况下google
将返回一个404 request
(这是预料之中的),在执行卷曲之后。