Forum Moderators: coopster

Message Too Old, No Replies

Help: Escaping an RSS (XML) Feed using PHP?

What's the best way to escape Text/HTML using PHP?

         

hiker_jjw

3:43 am on Mar 8, 2005 (gmt 0)



I've created an RSS 2.0 Feed for a friend of mine using PHP and MySQL. The author writes a ton of articles. I've worked out all the details of creating the feed in PHP, except for escaping characters for XML/RSS.

What's the best way to escape Text/HTML for an RSS 2.0 Feed using PHP? Can RSS descriptions contain HTML?

And... How might I escape out those "Mikrsooft" characters that I know the author will copy into the RSS descriptions?

Thanks in advance,
Jeff

vabtz

3:45 am on Mar 8, 2005 (gmt 0)



this is what I use:
$escaped_text = htmlentities( $text, ENT_QUOTES );

jusdrum

6:02 pm on Mar 8, 2005 (gmt 0)

10+ Year Member



What you need to do is wrap the content like this:

<description><![CDATA[<p>Content here</p>]]></description>

This will tell RSS readers to not parse anything between the description tags.

Hope this helps!