此问题是简单的。我会在PHP脚本中使用什么功能,从URL加载数据到一个字符串?

有帮助吗?

解决方案

CURL通常是一个很好的解决方案: http://www.php.net/curl


// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL and pass it to the browser
$html = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

其他提示

我认为你正在寻找

$url_data = file_get_contents("http://example.com/examplefile.txt");

使用文件封装器可以使用的file_get_contents访问HTTP资源(非常简单,只是GET请求,不POST)。对于更复杂的HTTP请求,你可以使用curl包装,如果您安装了。检查php.net获取更多信息。

查核史努比时,模拟web浏览器的PHP类:

include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->fetchtext("http://www.example.com");
$html = $snoopy->results;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top