I have a PHP (5.3) script that fetches data from a DB and pass it to android via JSON. The UTF-8 characters work only for Ä,Ü etc.
But not the russian and chinese letters!
Table
$createTableMessage = $db->prepare("CREATE TABLE IF NOT EXISTS message (
`id` int(11) unsigned NOT NULL auto_increment,
`fromusername` varchar(255) NOT NULL default '',
`tousername` varchar(255) NOT NULL default '',
`imageid` int(11) default null,
`text` varchar(255) default null,
`ispublic` int(11) default 0,
PRIMARY KEY (`id`))
CHARACTER SET utf8 COLLATE utf8_general_ci");
function 'Send message'
...
$answerarray[] = array(
"id" => $row['id'],
"countdown" => $row['-1'],
"answerText" => $row['text'],
"answerusername" => $row['fromusername'],
"filename" => $row[' '],
"country" => $row['country']
);
utf8_encode_deep($answerarray);
echo json_encode(array('answer'=>$answerarray));
function utf8_encode_deep (from the internet)
function utf8_encode_deep(&$input) {
if (is_string($input)) {
$input = utf8_encode($input);
} else if (is_array($input)) {
foreach ($input as &$value) {
utf8_encode_deep($value);
}
unset($value);
} else if (is_object($input)) {
$vars = array_keys(get_object_vars($input));
foreach ($vars as $var) {
utf8_encode_deep($input->$var);
}
}
}
utf8_encode_deep. PHP nowadays supports utf itself.