Reputation: 1369
Hi I am developing a mobile app using phonegap and I am querying the MySQL database through ajax (jsonp). However I have an issue when special characters are returned as they are displayed as "?" instead for example Ż.
At the moment in my PHP I have added this, however it did not do the trick:
header('content-type: application/json; charset=UTF-8');
Is anyone aware of any other charset that can be used which includes special characters like the above?
Upvotes: 0
Views: 134
Reputation: 14470
First thing is first
a) Fix the db tables Make sure that tables defined with proper character set e.g
CREATE TABLE `types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8
b) After connection to db ensure following things
[I also run following ]
SET character_set_client ='utf8',
character_set_connection ='utf8',
character_set_database ='utf8',
character_set_results ='utf8',
character_set_server ='utf8',
collation_connection ='utf8_general_ci',
collation_database ='utf8_general_ci',
collation_server ='utf8_general_ci'
c) Finally set proper content type for the html page
hope this will help you
Upvotes: 2
Reputation: 2958
According to the JSON implementation standards, all JSON data must be encoded in UTF format, the default format being UTF-8. But you can always use other UTF formats, such as UTF-32BE, UTF-16BE, UTF-32LE, UTF-16LE.
For detailed standards and information, visit ietf standard.
Upvotes: 0
Reputation: 14277
You're working with a MySQL database? So try to set a utf8 charset to the database connection like:
$conn = mysql_connect('localhost','user1','pass1',TRUE);
mysql_set_charset('utf8',$conn);
Or try UTF-8 encoding
string utf8_encode ( string $data )
Parameters:
data
An ISO-8859-1 string.
Return Values:
Returns the UTF-8 translation of data.
Upvotes: 0