Problem:
When Google Map uses Ajax to transmit data to the server in get mode, the server displays garbled URLs,
Zend Framework stores garbled data to MySQL, but the extracted data is a normal Chinese font,
Enter Chinese Characters in MySQL and garbled characters are displayed on the PHP webpage.
Solution:
1. Ajax url encoding needs to be converted. The following functions are used:
Public function js_unescape ($ str)
{
$ Ret = '';
$ Len = strlen ($ str );
For ($ I = 0; $ I <$ len; $ I ++)
{
If ($ str [$ I] = '%' & $ str [$ I + 1] = 'U ')
{
$ Val = hexdec (substr ($ str, $ I + 2, 4 ));
If ($ val <0x7f) $ ret. = chr ($ val );
Else if ($ val <0x800) $ ret. = chr (0xc0 | ($ val> 6). chr (0x80 | ($ val & 0x3f ));
Else $ ret. = chr (0xe0 | ($ val> 12 )). chr (0x80 | ($ val> 6) & 0x3f )). chr (0x80 | ($ val & 0x3f ));
$ I + = 5;
}
Else if ($ str [$ I] = '% ')
{
$ Ret. = urldecode (substr ($ str, $ I, 3 ));
$ I + = 2;
}
Else $ ret. = $ str [$ I];
}
Return $ ret;
}
Call example: $ row-> name = XmlController: js_unescape ($ this-> getRequest ()-> getParam ('name '));
2. Set all encoding-related fields to utf8 (php) or UTF-8.
MySQL includes databases, data tables, fields, and database connections.
Zend Framework includes data connections, views, and html output.
Ajax includes Javascript and XML file encoding and font encoding.
Zend Framework data connection encoding settings:
Reference http://phpeye.com/bbs/redirect.php? Fid = 2 & tid = 81 & goto = nextoldset
Zend_Db_Table: setdefaadapter adapter ($ dbAdapter );
Zend_Registry: set ('dbadapter ', $ dbAdapter );
$ DbAdapter-> query ("set names 'utf8 '");
If it is a PHP direct connection, the settings are as follows:
// Select all the rows in the markers table
$ Query = "SELECT * FROM markers WHERE 1 ";
// Add this sentence after the select database
Mysql_query ("set names utf8 ");
Mysql_query ("set character set utf8 ");
Mysql_query ("SET COLLATION_CONNECTION = 'utf8 _ general_ci '");