我正在尝试获取HTTP / HTTPS网站的内容。
我在本地运行XAMPP环境,并添加了php.ini:
extension=php_openssl.dll
allow_url_include = On
allow_url_fopen = On
我试图通过两种方式获取内容:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
也:
<?php
$stream = fopen('http://www.example.com', 'r'))
{
echo stream_get_contents($stream);
fclose($stream);
}
?>
当我在fopen或file_get_contents前面使用抑制标记“@”时,我总是得到警告,只是在行XY中说fopen或file_get_contents行所在的警告。但是没有从URL加载内容..
知道如何解决这个问题吗?
答案 0 :(得分:0)
您可以使用cURL进行尝试。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);