Search code examples
phputf-8rsslang

Dealing with multiple languages in rss feed


I am have problems dealing with different languages and codeignitors restful service by phil surgeon.

i am adding different language to my database which is set to utf-8unicode but when i pull it out its look random for some languages.

Like sinhalese ¹ç§°æžªå‡»æ¡ˆå«ŒçŠ¯å¯èƒ½ç»è¿‡è®­ç»ƒè£…å¤

Taken from gossip lanka their feed is http://www.gossiplankanews.com/feeds/posts/default?alt=rss

is this todo with their feed? because i cant save a item to my database and then return it as sinhalese

any suggestions where the problem may lie?

enter image description here


Solution

  • Your data are actually in UTF-8 while your MySQL connexion (I guess you have MySQL) is not configured to output UTF8.

    In PHP, as soon as you've established the connexion you have to turn the connexion option to import/export as UTF8.

    Like this :

    mysql_query("SET NAMES 'utf8'");
    

    Or with PDO :

    $pdo = new PDO(
        'mysql:host=hostname;dbname=defaultDbName',
        'username',
        'password',
        array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
    );