【问题标题】:file_get_contents is getting the wrong contentfile_get_contents 获取错误的内容
【发布时间】:2015-11-11 08:31:38
【问题描述】:

我在PHP 中使用file_get_contents 函数从运行良好的网站获取数据。但是对于这个网址:

http://benalman.com/code/projects/php-simple-proxy/ba-simple-proxy.php?url=http%3A%2F%2Fwww.google.com%2F

那里没有得到实际的内容。

<?php
  echo file_get_contents('http://benalman.com/code/projects/php-simple-proxy/ba-simple-proxy.php?url=http%3A%2F%2Fwww.goolge.com%2F');
?>  

【问题讨论】:

  • 很可能是某种重定向,因为youtube.com 将被重定向到 https。也许尝试直接访问https版本。

标签: php file-get-contents


【解决方案1】:

是的,它确实返回相同的内容,但您看不到它,因为它包含大量 HTML 和 Javascript。

以下是读取 JSON 内容的示例:

header("Content-Type: text/plain");
$json = file_get_contents('http://benalman.com/code/projects/php-simple-proxy/ba-simple-proxy.php?url=http%3A%2F%2Fwww.youtube.com%2F');
print_r(json_decode($json));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 2012-10-15
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    相关资源
    最近更新 更多