Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I was using a PHP script to convert Yahoo finance quotes to an HTML web page. But suddenly the web page stopped showing the data after a year of working perfectly and there were no code changes at all. Here is my code:

<table>
<tr>
<?php $fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s=VIP&f=l1c1p2rj1&e=.csv","r");
        $data = fgetcsv ($fp, 1000, ",") ?>
<td>Vimpel-Communications</td>
<td><?php echo $data[0] ?></td>
<td><?php echo $data[1] ?></td>
<td><?php echo $data[2] ?></td>
<td><?php echo $data[3] ?></td>
<td><?php echo $data[4] ?></td>
<td><?php echo $data[5] ?></td>
</tr>
</table>

And here is a test page of the actual site: http://bricadr.com/test.php Can anyone help or does anyone know what happened, or how I can fix this? Additionally, if anyone has a sever, can you see if this code works on your server? Perhaps my hosting company turned off some functionality that allowed this to previously work.

Thank you in advance!

Brian

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
204 views
Welcome To Ask or Share your Answers For Others

1 Answer

Update: Tested it on my server. When not parsed, commented in the HTML is a notice of a 301 redirect. The new page is "http://download.finance.yahoo.com/d/quotes.csv?s=VIP&f=l1c1p2rj1&e=.csv", simply change your URL. I've updated my below code if you would like to use it.

Anyway, here's a little effient-etized version of your code, using cURL because it is much faster than fopen. I also used explode because for some reason the cvs function was not working on my server.

$curl=curl_init();
curl_setopt ($curl,CURLOPT_URL,"http://download.finance.yahoo.com/d/quotes.csv?s=VIP&f=l1c1p2rj1&e=.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>";

Working here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...