The Zend Framework solves the problem of garbled Ajax, MySQL, and Zend Framework

Source: Internet
Author: User
Tags zend framework
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.