2014-09-03 99 views
0

我從表中提取數據以生成iTunes Feed。生成RSS Feed報價標記問題

爲類別標籤的格式爲:

<itunes:category text="Games &amp; Hobbies"> 
</itunes:category> 

我在一個表中取出該值即類別,從一個字段。

此:

<itunes:category text=".$data['category']."</itunes:category> 

輸出:

<itunes:category text=Games &amp; Hobbies</itunes:category> 
</itunes:category> 

相反的:

<itunes:category text="Games &amp; 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); 
?> 
+2

你缺少報價,轉義和關閉>。我建議使用XML庫來生成XML,或者至少要小心並使用htmlspecialchars()。 – ThW 2014-09-03 21:35:23

回答

1

看起來你只是缺少一些引號和右尖括號:

"...<itunes:category text=\"".$data['category']."\"></itunes:category>..." 
          ^^      ^^^      

如果你仍然得到語法錯誤,你解決這個問題後,用確切的錯誤信息更新您的問題。

+0

但「其他」標記值是XML節點值(開始和結束標記之間的值),而不是* attribute *值(節點本身的屬性)。這裏的'text'是一個* attribute *值,那些需要被引用。 – 2014-09-03 21:38:35

+0

謝謝你做到了! – MBM 2014-09-03 21:43:30

+0

不好意思,我已經做到了。 – MBM 2014-09-04 22:37:49