【问题标题】:replace php function 'file' using curl使用 curl 替换 php 函数“文件”
【发布时间】:2014-07-11 19:14:23
【问题描述】:

如何使用 curl 替换 php 函数“文件”?

$ego_quote = file($egoUrl); nicely put into an array.

$ego_quote[0] = error=OK
$ego_quote[1] = eta=Overnight
$ego_quote[2] = price=56.44

当我使用 CURL 时如何实现这一点?

原因,与函数“文件”相关的函数“fopen”在我们的生产服务器上不可用。

谢谢

【问题讨论】:

  • cURL 将返回更类似于file_get_contents 的内容。然后您可以在换行符处爆炸以达到与file 相同的效果

标签: php file curl fopen


【解决方案1】:

感谢Crayon Violent 在这篇文章中。

$ego_quote = explode("\n",$ego_quote);

这将为您提供与函数 file 相同的结果

$ego_quote[0] = error=OK
$ego_quote[1] = eta=Overnight
$ego_quote[2] = price=56.44

【讨论】:

    【解决方案2】:

    你可以这样做:

    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $egoUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $output = curl_exec($ch);
    
    curl_close($ch);
    
    echo $output;
    

    【讨论】:

      猜你喜欢
      • 2014-08-13
      • 2010-11-09
      • 1970-01-01
      • 2012-05-09
      • 2013-08-09
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多