Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文件“获取内容返回”;异常处理程序“中出错?”;?_Php_File Get Contents - Fatal编程技术网

Php 文件“获取内容返回”;异常处理程序“中出错?”;?

Php 文件“获取内容返回”;异常处理程序“中出错?”;?,php,file-get-contents,Php,File Get Contents,我在读取特定URL的内容时遇到问题。这个简单的脚本 <?php $str = @file_get_contents("http://neginmirsalehi.com"); echo $str; ?> 仅输出:“异常处理程序中出错。” 我也试过卷发,但同样的问题 这是对那个网站的某种保护吗?但奇怪的错误。您需要指示文件名而不仅仅是url吗 <?php $str = @file_get_contents("/dir/dir/file_name.extension"); e

我在读取特定URL的内容时遇到问题。这个简单的脚本

<?php
$str = @file_get_contents("http://neginmirsalehi.com");
echo $str;
?>

仅输出:“异常处理程序中出错。”

我也试过卷发,但同样的问题


这是对那个网站的某种保护吗?但奇怪的错误。

您需要指示文件名而不仅仅是url吗

<?php
$str = @file_get_contents("/dir/dir/file_name.extension");
echo $str;
?>

不,cURL可以工作,只需设置browser agent选项:

$ch = curl_init('http://neginmirsalehi.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
$result = curl_exec($ch);
echo $result;

此外,
file\u get\u contents
,以及带有代理的附加流上下文也可以工作:

$options  = array('http' => array('user_agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'));
$context  = stream_context_create($options);
$response = file_get_contents('http://neginmirsalehi.com', false, $context);
echo $response;

工作正常

抑制错误。当你试图解决你的问题时,你可能不想这样做。好吧…似乎是一个文件获取内容的问题。该站点运行的是php版本5.2.17。刚在运行php 5.6.6版的网站上试用过,效果很好!谢谢你,乔恩。我的错误:)但没有进一步的帮助。我想我只需要更新php。太好了。非常感谢。“浏览器代理”选项工作正常!:-)当然,杰约翰逊很高兴这有帮助
$u = 'http://neginmirsalehi.com';
$c = curl_init($u);
curl_setopt($c, CURLOPT_USERAGENT, 'moz');
$r = curl_exec($c);

print_r($r);