file_get_contents():没有这样的主机已知错误

Pau*_*raj 4 php networking

我正在使用该file_get_contents函数将URL转换为字符串:

$contents = file_get_contents("http://google.com");
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误:

file_get_contents()[function.file-get-contents]:php_network_getaddresses:getaddrinfo failed:没有这样的主机.

我怎样才能在本地主机中解决这个问题?

Vol*_*erK 8

您的"localhost"无法将名称google.com解析为IP地址,这意味着您的计算机无法/无法访问有效的DNS服务器.
这可能不仅影响php.试试ping google.com那台机器的控制台.这也是抱怨未知的主人吗?
解决问题所需的步骤取决于您的"本地主机"(操作系统,风格/分发......)以及它如何连接到互联网.