如何使用PHP製作一個完全簡單的靜態RSS提要?簡單的RSS與PHP?
爲什麼會這樣不行:
<?xml version="1.0"?>
<rss version=\"2.0\">
<channel>
<?php echo "<title>The Channel Title Goes Here</title>"; ?>
<description>The explanation of how the items are related goes here</description>
<link>http://www.directoryoflinksgohere</link>
<item>
<title>The Title Goes Here</title>
<description>The description goes here</description>
<link>http://www.linkgoeshere.com</link>
</item>
<item>
<title>Another Title Goes Here</title>
<description>Another description goes here</description>
<link>http://www.anotherlinkgoeshere.com</link>
</item>
</channel>
</rss>
我當然會需要做這個與MySQL自動更新,但現在我只需要知道如何赫克我可以結合甚至可以使用PHP和RSS 。
這實際上導致了RSS文件下載,而不是顯示:
<?php
echo "<?xml version=\"1.0\"?>
<rss version="2.0">
<channel>
<title>The Channel Title Goes Here</title>
<description>The explanation of how the items are related goes here</description>
<link>http://www.directoryoflinksgohere</link>
<item>
<title>The Title Goes Here</title>
<description>The description goes here</description>
<link>http://www.linkgoeshere.com</link>
</item>
<item>
<title>Another Title Goes Here</title>
<description>Another description goes here</description>
<link>http://www.anotherlinkgoeshere.com</link>
</item>
</channel>
</rss>";
?>
UPDATE:
這將輸出的RSS正確。幾乎。變量的值不被寫入,而是變量的名稱,例如它會寫「$吐司」而不是寫「是」。
<?php
$counter = 0;
$con=mysqli_connect("localhost","username","password","database");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = mysqli_query($con,"SELECT name FROM people");
while($row = mysqli_ffetch_array($sql)){
$test[$counter] = $row['name'];
$counter++;
}
$toast = "YES";
echo "
header(\"Content-Type: application/rss+xml; charset=ISO-8859-1\")
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<rss version="2.0">
<channel>
<title>The Channel Title Goes Here</title>
<description>$test[0]</description>
<link>http://www.directoryoflinksgohere</link>
<item>
<title>The Title Goes Here</title>
<description>$toast</description>
<link>http://www.linkgoeshere.com</link>
</item>
<item>
<title>Another Title Goes Here</title>
<description>Another description goes here</description>
<link>http://www.anotherlinkgoeshere.com</link>
</item>
</channel>
</rss>";
?>
無論我做什麼(來自其他站點的各種測試),Firefox始終嘗試下載RSS文件,而不是在使用PHP輸出內容時執行它。真的讓人感到沮喪,認爲簡單的事情是如此困難。 –