search
HomeBackend DevelopmentPHP ProblemSolution to php get Chinese garbled characters

php get Chinese garbled solution: first open the PHP file; then add the code "header("Content-type: text/html; charset=utf-8");"; finally output "rldecode($ _GET['plate']);" That's it.

Solution to php get Chinese garbled characters

Recommended: "PHP Video Tutorial"

The operating environment of this tutorial: Windows 7 system, PHP version 5.6, This method works for all brands of computers.

PHP uses get to solve the problem of garbled Chinese characters in the URL

1. Problem:

I originally planned to use the

code like this As follows:

<a href="list.php?plate=辖区动态" charset="utf-8" target="main">[查看辖区动态]</a>

The result obtained on the list.php page is - View [Jurisdiction Dongyi]

At first I guessed that the encoding of the Chinese character "state" may conflict with something. , so garbled characters appear.

2. Solution:

Use:

The code is as follows:

<a href="list.php?plate=<?php echo urlencode("辖区动态");?>" charset="utf-8" target="main">[查看]</a>

Then use the

code like this on the list.php page As follows:

<?php
header("Content-type: text/html; charset=utf-8");
if($_GET[&#39;plate&#39;])
echo $plate=urldecode($_GET[&#39;plate&#39;]);
?>

There will be no garbled characters and abnormal transmission.

Note that the encoding of the receiving GET page here needs to be consistent with the sending end!

About the string urlencode (string $str) function

This function facilitates encoding a string and using it in the request part of the URL, and it also facilitates passing variables to the next page.

Example 1 urlencode()

The code is as follows:

<?php
echo &#39;<a href="mycgi?foo=&#39;, urlencode($userinput), &#39;">&#39;;
?>

Example 2 urlencode() and htmlentities()

The code is as follows:

<?php
$query_string = &#39;foo=&#39; . urlencode($foo) . &#39;&bar=&#39; . urlencode($bar);
echo &#39;<a href="mycgi?&#39; . htmlentities($query_string) . &#39;">&#39;;
?>

The above is the detailed content of Solution to php get Chinese garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software