SharkBait Posted February 21, 2007 Share Posted February 21, 2007 I am having some issues with a RSS Feed creation script I have. The entries that are to go into the RSS feed have ampersands in them like or « or » and being RSS I believe they are not allowed to have ampersands in them (or so the RSS 2.0 Specification told me). Now I use html_entity_decode() and I thought that is supposed to convert things back to their proper character. Am I incorrect? Am I getting that function and htmlentities() confused? This is the bit of code I am using: <?php while($blog = mysql_fetch_array($query, MYSQL_ASSOC)) { // Strip HTML tags and convert any special characters $description = $blog['body']; $description = html_entity_decode($description); // Modify date to RFC 822 Specification $pubDate = date("D, d M Y H:i:s T", strtotime($blog['date_entered'])); // encode URL with - so that it is URL friendly (for Mod_rewrite) $url = str_replace(" ", "-", $blog['title']); // Actual body of the feed. Gets looped though and created for each Blog Entry $feed = "<item>\n <title>{$blog['title']}</title>\n <description>{$description}</description>\n <link>http://www.tingram.ca/blog/{$url}</link>\n <pubDate>{$pubDate}</pubDate>\n <guid>http://www.tingram.ca/blog/{$url}</guid>\n </item>\n\n"; // Write the current Blog Entry to the file fwrite($file, $feed); } ?> Any help is great! Quote Link to comment https://forums.phpfreaks.com/topic/39497-solved-html_entity_decode/ Share on other sites More sharing options...
Ninjakreborn Posted February 21, 2007 Share Posted February 21, 2007 Where did you read this in the specification. What little I did look at RSS so far, I have seen in multiple places that it's the correct way to do it. You need to have the html entities in order for it to be "validated". Correct me if I am wrong, were did you read this at specifically. Quote Link to comment https://forums.phpfreaks.com/topic/39497-solved-html_entity_decode/#findComment-190660 Share on other sites More sharing options...
SharkBait Posted February 21, 2007 Author Share Posted February 21, 2007 Might of been somewhere in here: http://blogs.law.harvard.edu/tech/rss But if you goto www.tingram.ca/rss.xml it fails because of the unknown entity which is the & (ampersand) Quote Link to comment https://forums.phpfreaks.com/topic/39497-solved-html_entity_decode/#findComment-190719 Share on other sites More sharing options...
Ninjakreborn Posted February 21, 2007 Share Posted February 21, 2007 http://www.xml.com/pub/a/98/08/xmlqna0.html Quote Link to comment https://forums.phpfreaks.com/topic/39497-solved-html_entity_decode/#findComment-190722 Share on other sites More sharing options...
SharkBait Posted February 21, 2007 Author Share Posted February 21, 2007 Ok so I read up on the internal and external entities. Now the code above will not convert the or « entities properly so when they get loaded into the XML file they crap out and the XML document won't display. How do I handle things like & etc when they are within the body of the RSS feed? Or am I not understanding what it is I need to do with my database information prior to loading it into an XML file? Quote Link to comment https://forums.phpfreaks.com/topic/39497-solved-html_entity_decode/#findComment-190788 Share on other sites More sharing options...
Ninjakreborn Posted February 21, 2007 Share Posted February 21, 2007 I know in another post in regards to html entities, there was a custom function http://www.phpfreaks.com/forums/index.php/topic,128079.0.html You will find someone that made entity safe functions, maybe that will help. Try that out, if not explain that is happening exactly. Is it encoding when you are not wanting it to, or vice-versa. (Sorry if it's spelt wrong). Quote Link to comment https://forums.phpfreaks.com/topic/39497-solved-html_entity_decode/#findComment-190805 Share on other sites More sharing options...
Ninjakreborn Posted February 22, 2007 Share Posted February 22, 2007 Hi, I was just concerned and wondering if you solved your problem yesterday or not. Let us know here if you didn't I can try and help more, maybe someone else will have ideas. WHere do you stand with your current problem right now, I don't want you just stuck here without an answer, you have helped me many times, I like the opprotunity to return the favor. So did you fix it, or are you still having problems with it? Quote Link to comment https://forums.phpfreaks.com/topic/39497-solved-html_entity_decode/#findComment-191371 Share on other sites More sharing options...
SharkBait Posted February 26, 2007 Author Share Posted February 26, 2007 I figured out what the solution is for my problem. I had to tell the XML parser to ignore the data within my <description> tags! I was looking over the Wordpress scripts and that is what tipped me off! <?php <description><!CDATA[{$description}]]></description> ?> Explaination: http://www.w3schools.com/xml/xml_cdata.asp Yay I'm soo happy I figured it out now I can use Full RSS Feeds with html formatting! Quote Link to comment https://forums.phpfreaks.com/topic/39497-solved-html_entity_decode/#findComment-194724 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.