Home > Backend Development > PHP Problem > How to solve the garbled problem with php urlencode

How to solve the garbled problem with php urlencode

藏色散人
Release: 2023-03-12 19:00:01
Original
2472 people have browsed it

php urlencode method to solve garbled characters: 1. Open the corresponding code file; 2. Encode "$row['title']"; 3. Query after obtaining the encoding.

How to solve the garbled problem with php urlencode

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

How does php urlencode solve the garbled code problem?

The urlencode function in php solves the garbled code problem

We are writing a php program Generally, little attention is paid to urlencode encoding when doing it. In order to avoid encoding errors, it is recommended that everyone.

When writing a program, whenever Chinese characters are transmitted using the get method, they are encoded with urlencode. After encoding, they can be used directly without decoding

. This is very useful when we use Chinese characters to query. Can avoid garbled code problems.

The following is an example of mine:

<A href="listlook.php?wenzhang=<? echo urlencode($row[&#39;title&#39;])?>&id=<? echo $row[&#39;id&#39;];?>"title="标题:<? echo mb_substr($row[&#39;title&#39;],0,40,&#39;utf-8&#39;);?>作者:<? echo $row[&#39;author&#39;];?>时间:<? echo $row[&#39;time&#39;];?>"><? echo mb_substr($row[&#39;title&#39;],0,15,&#39;utf-8&#39;);?>发布者<? echo $row[&#39;author&#39;]?></A>
Copy after login

This is a hyperlink, encoding $row['title']. Pass to the next page.

$query="SELECT * FROM news where type=&#39;".$_GET[&#39;wenzhang&#39;]."&#39;order by id desc limit 0, 10";
$result=mysql_query($query)or  die(&#39;查询失败:&#39;.mysql_error());
Copy after login

This is how to get the code and query it.

This can ensure that the encoding of the characters you query is consistent with the characters in your database.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to solve the garbled problem with php urlencode. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template