我尝试错误,以便即使用户输入不正确的网站它会回应一个错误消息,而那么不专业的file_get_contents处理错误的好方法
警告处理的file_get_contents方法:的file_get_contents(sidiowdiowjdiso):未能打开流: C中没有这样的文件或目录:\ XAMPP \ htdocs中\上线test.php的6
我想,如果我做一个尝试,抓住它就能捕获错误但不工作。
try
{
$json = file_get_contents("sidiowdiowjdiso", true); //getting the file content
}
catch (Exception $e)
{
throw new Exception('Something really gone wrong', 0, $e);
}
如果你想最起码读的URL,你应该确认他们看起来像URL第一,否则人们可以在服务器上读取文件。一个更好的选择可能是使用curl – 2013-04-21 12:05:32