我從表中提取數據以生成iTunes Feed。生成RSS Feed報價標記問題
爲類別標籤的格式爲:
<itunes:category text="Games & Hobbies">
</itunes:category>
我在一個表中取出該值即類別,從一個字段。
此:
<itunes:category text=".$data['category']."</itunes:category>
輸出:
<itunes:category text=Games & Hobbies</itunes:category>
</itunes:category>
相反的:
<itunes:category text="Games & Hobbies">
</itunes:category>
它周圍是否缺少類別講話標記。我已經嘗試了括號的各種組合,但不斷收到語法錯誤。
低於全部腳本:
<?php
include("authenticate.php");
$user = $_SESSION['UserName'];
$initialdata = $result = mysql_query("SELECT * FROM ccregisterfeed WHERE username = '$user'");
$initdata = mysql_fetch_assoc($initialdata);
$result = mysql_query("SELECT * FROM ccshowcontent JOIN ccaudio ON ccshowcontent.id = ccaudio.id WHERE ccshowcontent.username = '$user' ORDER BY ccshowcontent.id DESC")
or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$items[] = $row;
}
function createXML($items,$data){
$xml = "<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">
<channel>
<title>".$data['feedtitle']."</title>
<link>".$data['websitelink']."</link>
<language>en-GB</language>
<copyright>".$data['copyright']."</copyright>
<itunes:subtitle>".$data['subtitle']."</itunes:subtitle>
<itunes:author>".$data['author']."</itunes:author>
<description>".$data['feeddescription']."</description>
<itunes:image href=".$data['imagelink']."/>
<itunes:category text=".$data['category']."</itunes:category>
<title>".$data['feedtitle']."</title>
<link>".$data['websitelink']."</link>
<category text=>".$data['category']."</category>
<pubDate>".date("D, d M Y H:i:s O", strtotime($data['pubdate']))."</pubDate>
<language>en-us</language>
<image>
<title>".$data['feedtitle']."</title>
<link>".$data['websitelink']."</link>
<url>".$data['imagelink']."</url>
<description>".$data['imagetitle']."</description>
</image>";
$audiodir = "http://thetradingcardgenerator.com/MP3/";
foreach($items as $key => $item){
$path = $audiodir.$item['path'];
$pdate = strtotime($item['pubdate']);
$date = date("D, d M Y H:i:s O", $pdate);
$xml .="
<item>
<title>".$item['title']."</title>
<description>".$item['description']."></description>
<guid>".$path."</guid>
<pubDate>".$date."</pubDate>
<itunes:duration>".$data['imagelink']."</itunes:duration>
</item>";
}
$xml .="
</channel>
</rss>";
return $xml;
}
$rss = createXML($items,$initdata);
//echo "feed updated!";
$filename = "itunes" . strtolower(str_ireplace(" ", "", $initdata['feedtitle']) . ".xml");
file_put_contents($filename,$rss);
header("Location: ccupload.php?message=".urlencode("Content Added <br/> Feed Updated"));
// var_dump ($filename);
?>
你缺少報價,轉義和關閉>。我建議使用XML庫來生成XML,或者至少要小心並使用htmlspecialchars()。 – ThW 2014-09-03 21:35:23