[英]PHP file_get_contents and stream return warning instead of content
I am trying to get the content of a HTTP / HTTPS website. 我正在尝试获取HTTP / HTTPS网站的内容。
I have a running XAMPP environment locally with these additions to the php.ini: 我在本地运行XAMPP环境,并对php.ini进行了以下添加:
extension=php_openssl.dll
allow_url_include = On
allow_url_fopen = On
I tried to get the content with 2 ways: 我尝试通过两种方法获取内容:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
also: 也:
<?php
$stream = fopen('http://www.example.com', 'r'))
{
echo stream_get_contents($stream);
fclose($stream);
}
?>
Also when I use the suppression tag "@" in front of fopen or file_get_contents I get warnings all time only saying warning in line XY, where the fopen or file_get_contents line is located. 同样,当我在fopen或file_get_contents前面使用抑制标签“ @”时,我总是收到警告,只在x行或fopen或file_get_contents所在的位置说警告。 But no content is loaded from the URL..
但没有从URL加载任何内容。
Any idea how to solve this? 任何想法如何解决这个问题?
You can try it with cURL. 您可以使用cURL尝试。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.