【问题标题】:PHP: easiest way to read a remote file into a stringPHP:将远程文件读入字符串的最简单方法
【发布时间】:2014-05-30 04:49:11
【问题描述】:

这似乎是最基本的东西,也许太基本以至于没有人愿意提及它。我已经学习了所有基本的 PHP 语法和一些函数,例如 fread()fopen(),但是我找不到将 URL 下载到字符串中的好方法。现在我最好的尝试是:

$someFile = fopen("http://www.pastats.com/report/winners?start=1386916400&duration=86400", r);
$someData = fread($someFile, filesize("http://www.pastats.com/report/winners?start=1386916400&duration=86400") );

但它不起作用,因为如果我没有写权限,filesize 显然不起作用。我知道必须有一种非常简单的方法来做到这一点。

【问题讨论】:

    标签: php file url


    【解决方案1】:

    假设您的权限设置正确(allow_url_fopen 设置为 true),听起来确实如此,那么file_get_contents() 是您最好的选择。否则你会想use PHP's cURL functions

    【讨论】:

      猜你喜欢
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      相关资源
      最近更新 更多