【问题标题】:file_get_contents() not working for 2 url'sfile_get_contents() 不适用于 2 个 url
【发布时间】:2018-11-10 21:13:10
【问题描述】:

我正在使用file_get_contents() 函数从 Google 获取两个网页。我的代码是:

var_dump(htmlspecialchars(html_entity_decode(file_get_contents('https://www.google.com/search?q=moscow+russia&start=30'))));

var_dump(htmlspecialchars(html_entity_decode(file_get_contents('https://www.google.com/search?q=ice&start=00'))));

file_get_contents 函数适用于第一个 URL,但不适用于第二个 URL。有什么问题?

【问题讨论】:

标签: php file-get-contents


【解决方案1】:

因为有字符,htmlspecialchars不能处理。 file_get_contents 正在工作。

试试ENT_SUBSTITUTE 选项:

var_dump(htmlspecialchars(html_entity_decode(file_get_contents('https://www.google.com/search?q=moscow+russia&start=30'))));

https://secure.php.net/manual/en/function.htmlspecialchars.php

【讨论】:

    猜你喜欢
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    相关资源
    最近更新 更多