通过PHP的雅虎CSV到HTML - 不再工作 [英] Yahoo CSV to HTML via PHP -- no longer works

查看:229
本文介绍了通过PHP的雅虎CSV到HTML - 不再工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP脚本将Yahoo财务报价转换为HTML网页。但突然,网页停止显示数据后一年的工作完美,没有任何代码更改。这是我的代码:

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>

这里是实际网站的测试页: http://bricadr.com/test.php
任何人都可以帮助或没有人知道发生了什么,或者如何解决这个问题?此外,如果任何人有一个服务器,你能看到这个代码是否在您的服务器上工作?

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.

提前感谢!

Brian

推荐答案

更新:在我的服务器上测试。当未解析时,在HTML中注释的是301重定向的通知。新页面为http://download.finance.yahoo.com/d/quotes.csv?s=VIP&f=l1c1p2rj1&e=.csv,只需更改您的网址。我已经更新了我的下面的代码,如果你想使用它。

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.

无论如何,这里有一个效率化版本的代码,使用cURL因为它< href =http://stackoverflow.com/questions/555523/file-get-contents-vs-curl-what-has-better-performance>比fopen快很多。我也使用了爆炸,因为某些原因cvs函数不在我的服务器上工作。

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>";

工作此处

这篇关于通过PHP的雅虎CSV到HTML - 不再工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆