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

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.




Related Posts

»  Create Twitter RSS Of Your Tweets Based On Keywords
 

As i started testing and creating a script for my blog sidebar column, many asked me how i did it. Well basically it is a very simply PHP script which uses Simplepie engine to create a RSS feed based on keyword matching. Basically my current sidebar script will show an RSS feed of my tweets [...]

»  Power of file_get_contents() PHP function
 

Ever since the introduction of PHP5, we have been getting a lot of complaints that most webhostings are actually restricting the include() feature of remote files/links. This is actually a default settings in PHP5 to avoid hacks and DDos attacks. This simply means only local files can be included in any PHP applications. First workaround [...]

»  Remove Unwanted Space From A Form Element
 

As i was creating the new Theme for my blog, i ran into a problem which i always face while creating a form based script. Whenever i try to create a form based element, there will somehow be a space after the element which really spoils my theme. No matter what i do, the unwanted [...]



Recommended



Comments

1. Steve Meisner @ 02:25 pm on March 25th, 2009

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


Leave a comment:

Your comment :

 
About Me

I'm ramesh from Perak, MY. Blogging is my hobby and you can get the best of me by:

» Subscribe via Feed | Mail
» Follow Me On Twitter
» Follow Me On FriendFeed


Site Menu



Latest Photosets



Top Posts



Followers

Eric Yeow
0 followers [msg]
Meteora
79 followers [msg]
jminkler
1537 followers [msg]
BoliBol
85 followers [msg]
novinthen
130 followers [msg]


 

page made and maintained by mesh