0
votes

I'm trying to build a rss feed for my website when I run the rss page I get this error:

XML Parsing Error: not well-formed Location: http://localhost/projects_rss.php Line Number 1, Column 2:

here is my code or at least xml part of it

foreach($projects_array as $projects_array){    
    $parr[]= array(
      'title' =>  (string)$projects_array->title,
      'description'  =>  (string)$projects_array->text,
      'link'  =>  (string)'www.imjobs.com/project.php?project='.$projects_array->id ,
      'date'  =>  (string) date("D, d M Y H:i:s O", $projects_array->datee),
      );
}

header("Content-Type: text/xml;charset=iso-8859-1");

    echo '<?xml version="1.0" encoding="ISO-8859-1"?>
    <rss version="2.0">
    <channel>
    <link>http://www.mysite.com</link>
    <language>en-us</language>
    <copyright>Copyright (C) 2011 mimjobs.com</copyright>
    <pubDate>' . date("D, d M Y H:i:s O", time()) . '</pubDate>';
    foreach ($parr as $p ){

    echo '<item>';
    echo '<title>' . $p['title'] . '</title>';
    echo '<description>'.$p['description'].'</description>';
    echo '<link>' . $p['link'] . '</link>';
    echo '<pubDate>' . $date . '</pubDate>';
    echo '</item>';
    }
    echo '</channel>';
    echo '</rss>';
    ?>
1

1 Answers

0
votes

The problem is you're echoing special characters such as "<" and ">". You need to either wrap the output in htmlspecialchars() or just replace all occurrences of "<" and ">" with &lt; and &gt; respectively. Note there are other characters which may need to have this type of treatment so htmlspecialchars() (or htmlentities()) may be your safest option.