我正在使用下面的代码来获取洛杉矶的当前时间(小时)
$response_xml_data = file_get_contents('http://www.earthtools.org/timezone-1.1/34.05223/-118.24368');
$data = simplexml_load_string($response_xml_data);
$dt = new DateTime($data->localtime);
$time = $dt->format('H:i:s');
list($hour, $min, $sec) = explode(':', $time);
echo $hour;此代码脱机运行良好,但当我将该文件放到网上时,会收到以下警告消息:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in [PHP file name and line number]Warning: file_get_contents(http://www.earthtools.org/timezone-1.1/34.05223/-118.24368)
[function.file-get-contents]: failed to open stream: no suitable wrapper could be found in [PHP file name and line number]
看来我使用了错误的方法读取XML数据,请提出建议?
发布于 2013-12-05 14:49:25
这意味着在您称为“联机”的服务器上,HTTP包装器对于PHP中的文件函数是禁用的。
发布于 2013-12-05 14:51:11
我认为这是因为您的服务器上禁用了php的allow_url_fopen设置。这就阻止了https包装器的可用,或者类似的东西。
您可以在您的php.ini文件中启用,这应该会消除错误。不确定其他的影响,所以在你改变之前要知道你在改变什么。
参考文献:http://php.net/manual/en/filesystem.configuration.php
发布于 2013-12-05 14:51:28
基本上,您只需要覆盖php默认配置,打开php.ini即可。
allow_url_fopen = ON
https://stackoverflow.com/questions/20402959
复制相似问题