【发布时间】:2012-07-12 08:10:11
【问题描述】:
当我尝试解析 google rss 提要时,我收到 Network error: 500 internal server error in chrome 和 firefox 开发者工具。下载 rss 提要(使用 curl)的第一部分工作正常。
我在以下位置找到了这个示例:http://www.joevasquez.info/development/parsing-xml-feeds-with-php-rss-and-atom/#more-63
有人可以指出我做错了什么吗?谢谢。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if (function_exists("curl_init")){
$ch=curl_init();
//curl_setopt($ch,CURLOPT_URL,'http://www.joevasquez.info/feed/');
curl_setopt($ch,CURLOPT_URL, 'http://news.google.com/news?hl=en&topic=t&output=rss');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//curl_setopt($ch,CURLOPT_HEADER,0);
$data=curl_exec($ch);
curl_close($ch);
//print($data);
$doc=new SimpleXmlElement($data,LIBXML_NOCDATA);
if (isset($doc->channel)) parseRSS($doc);
function parseRSS($xml){
$cnt=count($xml->channel->item);
for ($i=0;$i<$cnt;$i++){
$url=$xml->channel->item[$i]->link;
$title=$xml->channel->item[$i]->title;
$desc=$xml->channel->item[$i]->description;
echo '<a href="'.$url.'">'.$title.'</a>'.$desc.'<br>';
}
}
?>
</body>
</html>
【问题讨论】:
-
每次 PHP 生成 500 错误时,都会在错误日志中附上一个有用的条目。鉴于脚本的开头是直接输出而不是
<?php标签,很可能是解析错误。查看您的网络服务器错误日志并报告您发现的任何消息。 -
我尝试在
-
我现在正在检查错误日志