如何从网址PHP加载任意数据?

Gam*_*eak 0 php url scripting load

这个问题很简单.我将在PHP脚本中使用什么函数将URL中的数据加载到字符串中?

che*_*ews 5

我想你在找

$url_data = file_get_contents("http://example.com/examplefile.txt");
Run Code Online (Sandbox Code Playgroud)


Kei*_*Jr. 5

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);
Run Code Online (Sandbox Code Playgroud)