简体   繁体   English

PHP file_get_contents和流返回警告而不是内容

[英]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.

相关问题 如何获得file_get_contents()警告而不是PHP错误? - How to get file_get_contents() warning instead of the PHP error? 在PHP中突然发出file_get_contents警告 - file_get_contents warning suddenly in PHP PHP 警告:file_get_contents - PHP Warning: file_get_contents php file_get_contents 与 ajax 内容 - php file_get_contents with ajax content 如何修复php警告:file_get_contents?无法打开流:HTTP请求失败 - How to fix php Warning: file_get_contents?failed to open stream: HTTP request failed 警告:file_get_contents 无法打开流:连接被拒绝 php - Warning: file_get_contents failed to open stream: Connection refused php PHP file_get_contents返回错误 - PHP file_get_contents return error 警告:file_get_contents(image.jpg)[function.file-get-contents]:无法打开流:php中没有这样的文件或目录 - Warning: file_get_contents(image.jpg) [function.file-get-contents]: failed to open stream: No such file or directory in php 警告:file_get_contents(text.php?text = ae)[function.file-get-contents]:无法打开流:无错误 - Warning: file_get_contents(text.php?text=a-e) [function.file-get-contents]: failed to open stream: No error in 如何修复由 JSON 内容中的负数引起的 php file_get_contents 警告? - How do I fix a php file_get_contents warning caused by a negative number in JSON content?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM