Forum Moderators: coopster

Message Too Old, No Replies

How to handle special characters in RSS generated by PHP?

htmlspecialchars not work

         

iProgram

3:30 pm on Jul 15, 2004 (gmt 0)

10+ Year Member



I generate RSS 2.0 using PHP from mysql DB, for example:
echo "<title>" . $title . </title>\n";
echo "<link>" . $link . </link>\n";
echo "<description>" . $description . "</description>\">

The problem is, sometime there are special characters in $description or $title, for example, trademark symbol. Is there a function which can remove these characters? I tried to use htmlspecialchars ($description), which only work with HTML tags.

john_k

3:37 pm on Jul 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you mean that the text contains HTML entities such as "&tm;" or "&copy;" (as opposed to the specific ASCII code for TM), then the answer is to escape the ampersand with the ampersand entity. This will leave you with:
&amp;tm;
&amp;copy;
&amp;quot;
etc.

Some news reader services (like Yahoo's) don't unescape this sequence though.

john_k

3:40 pm on Jul 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Forgot an important aspect of that. The first entity you need to fix is the ampersand entity. So you will wind up with: &amp;amp;