0

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

2
  • you're trying to dump table cells without a <table> or even <html><body> to wrap it all in. If you want something formatted in a certain way, YOU have to write the code to make that formatting happen. Commented Mar 16, 2014 at 15:09
  • I wrote the code and wrap the results with <table>, <tr>, <td> but again I do not manage to get it properly displayed as it is in ichart.yahoo.com/… Commented Mar 16, 2014 at 15:31

1 Answer 1

1
<?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("\n", $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>";
 ?>
Sign up to request clarification or add additional context in comments.

3 Comments

No problem, do you have any idea how can I create a chart out of it?
This (pchart.net) is one I have used for charts. It is quite simple to use (wiki.pchart.net/doc.basic.syntax.html)
It will help me a lot if you could tell me how to access just one cell's content. I am trying echo $rows[0][0]; but it only takes the letter D.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.