【发布时间】:2023-03-18 14:25:01
【问题描述】:
我写了一个这样的PHP代码
$site="http://www.google.com";
$content = file_get_content($site);
echo $content;
但是当我从$site 中删除“http://”时,我收到以下警告:
警告: file_get_contents(www.google.com) [function.file-get-contents]:失败 打开流:
我尝试了try 和catch,但没有成功。
【问题讨论】:
-
也是一个有趣的方法:stackoverflow.com/questions/6718598/…
-
将 try-catch 与 set_error_handler-function 一起使用,如此处所述stackoverflow.com/a/3406181/1046909
-
如果您从 url 中删除 http://,那么您正在本地磁盘上查找文件“www.google.com”。
-
这怎么能得到如此多的关注和支持。为什么要删除协议信息。即使在 2008 年,你也有 FTP 和 HTTPS。
标签: php function exception warnings file-get-contents