PHP正在显示所有其他php文件,但此文件是唯一的。它为nfl分数创建一个rss feed。当我查看它时,我看到的是代码。我相信我必须错过Apache2中的某个模块或其他什么,但我是空白的。任何帮助是极大的赞赏。下面是代码。此代码在我的个人hostgator Web服务器帐户上运行良好,这使我相信它是我的本地服务器上的apache2配置的问题。我在三个不同的apache2服务器上尝试了同样的问题。
<?
function get_content($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n";
echo "<!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS 0.91//EN\"\n";
echo " \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">\n\n";
echo "<rss version=\"0.91\">\n\n";
echo "<channel>\n";
echo "<title>NFL Scores</title>\n";
echo "<link>http://www.nfl.com/</link>\n";
echo "<description>NFL Scores</description>\n";
echo "<language>en-us</language>\n";
echo "<image>\n";
echo " <title>NFL Scores</title>\n";
echo " <url>http://www.mpiii.com/scores/nfl.gif</url>\n";
echo " <link>http://www.nfl.com</link>\n";
echo "</image>\n";
echo "<webMaster>info@nfl.com</webMaster>\n";
$content = get_content ("http://sports.espn.go.com/nfl/bottomline/scores");
$content_array=explode("&", $content);
$scorearray = array();
$i=0;
foreach($content_array as $content) {
if (strpos($content, "_left")) {
$equalpos = strpos($content, "=");
$end = strlen($content);
$title = substr($content, ($equalpos+1), $end);
$title = str_replace("^", "", $title);
$title = str_replace("%20", " ", $title);
$title = ucwords(str_replace("END OF 4TH", "Final", $title));
$title = str_replace('( ', '(', ucwords(str_replace('(', '( ', $title)));
$title = str_replace("FINAL", "Final", $title);
$scorearray[$i]["title"] = $title;
}
if (strpos($content, "_url")) {
$equalpos = strpos($content, "=");
$end = strlen($content);
$url = substr($content, ($equalpos+1), $end);
$url = str_replace("^", "", $url);
$url = str_replace("%20", " ", $url);
$scorearray[$i]["url"] = $url;
$i++;
}
}
foreach($scorearray as $score) {
echo "<item>\n";
echo "<title>".$score["title"]."</title>\n";
echo "<link>".$score["url"]."</link>\n";
echo "</item>\n";
}
echo "</channel>\n";
echo "</rss>\n";
?>