Problem:
When you use Ajax to send data to a server on Google maps, the server side is displayed as a URL garbled.
Zend Framework to MySQL storage data is garbled, but extracted is normal Chinese font,
MySQL input in Chinese, displayed on the PHP page is garbled.
How to resolve:
1. The URL encoding of Ajax needs to be converted, I use the following function:
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;
}
Invocation Example: $row->name =xmlcontroller::js_unescape ($this->getrequest ()->getparam (' name '));
2. Place all coding-related places as UTF8 (PHP) or utf-8
MySQL includes databases, data tables, fields, database connections.
The Zend Framework includes data connections, views, and HTML output.
Ajax includes Javascript, 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::setdefaultadapter ($dbAdapter);
Zend_registry::set (' Dbadapter ', $dbAdapter);
$dbAdapter->query ("SET NAMES ' UTF8 '");
If it is a direct connection to PHP, then this setting:
Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
Gator 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 '");
The above describes the Zend framework to solve the Ajax, MySQL and Zend framework garbled problem, including the Zend framework aspects of the content, I hope to be interested in PHP tutorial friends helpful.