


zend framework solves the garbled problem of Ajax, MySQL and Zend Framework
Problem:
When using Ajax to transmit data to the server in get mode on Google Map, the server side displays the url as garbled characters.
Zend Framework stores data in MySQL as garbled characters, but when extracted, it is normal Chinese font.
Input Chinese into MySQL. The code displayed on the PHP web page is garbled.
Solution:
1. Ajax url encoding 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;
}
Calling example: $row->name =XmlController::js_unescape( $this->getRequest()->getParam('name') );
2. Set all encoding areas to utf8(php) Or utf-8
MySQL includes database, data table, fields, and database connection.
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 PHP connection, set it like this:
// 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'");
The above introduces the zend framework to solve the garbled problem of Ajax, MySQL and Zend Framework, including the content of zend framework. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Using ZendFramework with PHP: Quick Start Guide ZendFramework is an open source, PHP-based web application framework that is powerful and easily extensible. ZendFramework contains many useful components that can help you build efficient web applications. This article will introduce how to use ZendFramework in PHP to help you get started quickly. Install ZendFramewo

Implementing efficient database queries through ZendFramework middleware Introduction In the development process, database queries are an inevitable part. An efficient database query can greatly improve system performance and user experience. ZendFramework is a widely used PHP framework with powerful database operation functions. This article will introduce how to implement efficient database queries through ZendFramework middleware and provide corresponding code examples. 1. Understanding ZendF

ZendFramework is a powerful development framework that helps developers quickly build high-performance, scalable PHP applications. Among them, middleware is an important concept in ZendFramework, which can help us implement full-text search and paging functions. This article will introduce how to use middleware in ZendFramework to implement these two functions and provide code examples. 1. Full-text search function Full-text search is one of the common functions in modern applications.

ZendFramework Middleware: Adding OAuth and OpenID Login Support to Applications User authentication is a critical feature in today's Internet applications. In order to provide better user experience and security, many applications choose to integrate third-party login services, such as OAuth and OpenID. In ZendFramework, we can easily add OAuth and OpenID login support to our applications through middleware. First, we need to install Ze

ZendFramework middleware: Provides email notification and message push functions Introduction: With the development of the Internet and the popularity of smartphones, email notification and message push have become one of the commonly used functions in modern software development. In ZendFramework, we can use middleware to implement email notification and message push functions. This article will introduce how to use ZendFramework middleware to implement email notifications and message push, and provide corresponding code examples. 1. Preparation work in

ZendFramework is an open source framework based on PHP that provides many powerful tools and components for building scalable web applications. This article will introduce how to use ZendFramework's middleware to add social login functionality to web applications. Middleware is code that is executed before or after a request enters your application. It allows developers to customize and extend the process of handling requests. ZendFramework provides a flexible way to

When you decide to develop an ERP system, choosing a suitable framework is crucial. Here we will compare the two PHP frameworks CodeIgniter and ZendFramework to help you find a framework that is more suitable for your ERP system development. CodeIgniter and ZendFramework are popular PHP frameworks. They all provide many features and are extensible and maintainable. However, these two frameworks differ significantly in some aspects and are more suitable for some applications.

ZendFramework middleware: Adding Alipay and WeChat payment functions to applications Introduction: With the popularity of mobile payments, Alipay and WeChat payment have become essential payment methods in many applications. This article will introduce how to use ZendFramework middleware to add Alipay and WeChat payment functions to the application. By studying this article, you will learn how to use middleware to simplify the payment process and apply it to your actual projects. 1. Preparation Before starting, you
