This question is simple. What function would I use in a PHP script to load data from a URL into a string?
这个问题很简单。我将在PHP脚本中使用什么函数将URL中的数据加载到字符串中?
4 个解决方案
#1
5
CURL is usually a good solution: http://www.php.net/curl
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);
#2
5
I think you are looking for
我想你在找
$url_data = file_get_contents("http://example.com/examplefile.txt");
#3
2
With file wrappers you can use file_get_contents to access http resources (pretty much just GET requests, no POST). For more complicated http requests you can use the curl wrappers if you have them installed. Check php.net for more info.
使用文件包装器,您可以使用file_get_contents来访问http资源(几乎只是GET请求,没有POST)。对于更复杂的http请求,如果安装了curl包装器,则可以使用它们。查看php.net了解更多信息。
#4
1
Check out Snoopy, a PHP class that simulates a web browser:
查看Snoopy,一个模拟Web浏览器的PHP类:
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->fetchtext("http://www.example.com");
$html = $snoopy->results;
#1
5
CURL is usually a good solution: http://www.php.net/curl
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);
#2
5
I think you are looking for
我想你在找
$url_data = file_get_contents("http://example.com/examplefile.txt");
#3
2
With file wrappers you can use file_get_contents to access http resources (pretty much just GET requests, no POST). For more complicated http requests you can use the curl wrappers if you have them installed. Check php.net for more info.
使用文件包装器,您可以使用file_get_contents来访问http资源(几乎只是GET请求,没有POST)。对于更复杂的http请求,如果安装了curl包装器,则可以使用它们。查看php.net了解更多信息。
#4
1
Check out Snoopy, a PHP class that simulates a web browser:
查看Snoopy,一个模拟Web浏览器的PHP类:
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->fetchtext("http://www.example.com");
$html = $snoopy->results;