MBM
MBM

Reputation: 127

Generating RSS Feed Quote Marks Issue

I'm pulling data from a table to generate an itunes feed.

The format for the category tag is :

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

I'm fetching this value i.e. the category, from a field in a table.

This :

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

Outputs :

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

Instead of :

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

It's missing the speech marks around the category. I've tried all sorts of combinations of brackets but keep getting syntax errors.

Full script below :

<?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);
?>

Upvotes: 0

Views: 135

Answers (1)

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107576

Looks like you're just missing some quotes and a closing angle bracket:

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

If you're still getting syntax errors after you fix that, update your question with the exact error message.

Upvotes: 1

Related Questions