dongtidai6519 2014-03-16 15:06
浏览 65
已采纳

来自cURL的PHP​​多维数组

I am trying to export the results from querying "http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=2000&d=0&e=31&f=2010&g=w&ignore=.csv" with PHP and cURL.

I am using the following piece of code:

<?php
$curl=curl_init();
curl_setopt ($curl,CURLOPT_URL,"http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&     c=2000&d=0&e=31&f=2010&g=w&ignore=.csv");
curl_setopt ($curl,CURLOPT_HEADER,0);
ob_start();
curl_exec ($curl);
curl_close ($curl);
$data=ob_get_clean();
$data=explode(",",$data);
$data=str_replace('"','',$data);
foreach ($data as $results)
{
echo "<td>$results</td>";
}

?>

How can show the results in Table format just like they appear in "http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=2000&d=0&e=31&f=2010&g=w&ignore=.csv" ??

I doing something wrong in echo ... but I am not sure how to do it.

Yours

  • 写回答

1条回答 默认 最新

  • duanlei20082008 2014-03-16 15:19
    关注
    <?php
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, "http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=2000&d=0&e=31&f=2010&g=w&ignore=.csv");
        curl_setopt($curl, CURLOPT_HEADER, 0);
        ob_start();
        curl_exec($curl);
        curl_close($curl);
        $data = ob_get_clean();
    
        $rows = explode("
    ", $data);
        echo "<table border='1'>";
        foreach($rows as $row) {
          echo "<tr>";
          $cols = explode(',', $row);
          foreach($cols as $col)
            echo "<td>$col</td>";
          echo "</tr>";
        }
        echo "</table>";
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?