SimplePie and mySQL Special Character Issue
Posted at 2:25 pm on July 4th, 2008 in Tips & Tricks Hits: 2,302

Simplepie is one of the coolest RSS script ever to be created. It lets you create RSS feed, aggregate the feed and enhance the feed. Recently i am working on a new project which converts wordpress into a social bookmarking site via auto RSS feeding. I am still doing it and i got stuck with so many problems along the way. One of it the main problem i faced was writing obtained RSS feed as entries into mySQL. As i was doing this i noticed that all string based entries passed to the database becomes special (weird) characters.

Example:

Hello World!

Above is the string based post entry into the mySQL. But when checked in mySQL table and also when re-retrieved from the database, the result turns out to be like below.

Became:

HeÄll€o World!€Ä

I almost fainted finding solution for this and later when i searched the net for answers, i realized that there are many others like me which couldn’t find an answer to this solution and even if there was any fixed advised, they just didn’t seem to work.

After 1 whole day of checking finally i realized that the reason why this error came is because of the mismatch of character encoding with SimplePie and mySQL. My database was set to the default ISO character encoding, while SimplePie by default produces UTF-8 encoding. So how did i fix the problem? I left my database with the default ISO character encoding and change the SimplePie script page to the matching encoding.

The Code For SimplePie:

include('simplepie.inc');
$feed->set_output_encoding('ISO-8859-1');
$feed->init();

Just include the above code into your SimplePie script pages and it should fix the problem. Or alternatively without adding this code you can change the mySQL database character encoding to UTF-8.


|

  • http://www.stevemeisner.us/wordpress Steve Meisner

    Thanks so much, this saved me a ton of time, I’m sure.

 
About Me

I'm ramesh from Perak, Malaysia. Blogging is my hobby hence this blog is my second home to share my life, interests and etc. One can always interact with me by using the mediums below.



Blog Menu

» Main Page
» Blogging ( 137 | rss )
» Info Tech ( 43 | rss )
» Mesh Views ( 3 | rss )
» My Mesh ( 17 | rss )
» My Poems ( 6 | rss )
» My Workshop ( 16 | rss )
» myIndians-World ( 45 | rss )
» Places & Events ( 62 | rss )
» Shoot Me ( 17 | rss )
» Tips & Tricks ( 21 | rss )
» Contact Me


Micro Mesh



Get Updates



 

page made and maintained by mesh