This question is simple. What function would I use in a PHP script to load data from a URL into a string?
+2
A:
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.
ehassler
2008-12-04 01:46:57
+2
A:
I think you are looking for
$url_data = file_get_contents("http://example.com/examplefile.txt");
chews
2008-12-04 01:47:38
OK, it works. But not for wikipedia.org.For example:` file_get_contents("http://en.wikipedia.org/wiki/apple");`failsThis is a problem because this is the site that I am trying to load data from"
GameFreak
2008-12-04 01:56:54
OK, NOW it works. Even though I didn't change anything.
GameFreak
2008-12-04 02:05:56
+2
A:
CURL is usually a good solution: 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);
Keith Palmer
2008-12-04 15:10:41
A:
Check out Snoopy, a PHP class that simulates a web browser:
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->fetchtext("http://www.example.com");
$html = $snoopy->results;
Derek Kurth
2008-12-04 21:04:23