Home >Backend Development >PHP Problem >How to transcode Chinese in URL with PHP?

How to transcode Chinese in URL with PHP?

Guanhui
GuanhuiOriginal
2020-07-22 13:51:573245browse

How to transcode Chinese in URL with PHP?

#How does PHP transcode the Chinese in the URL?

In PHP, you can use the function "urlencode()" to encode the URL. The function of this function is to encode the URL string. Its syntax is "urlencode($str)". If you want to use encoding The resulting data can be decoded through "urldecode".

Sample code

<?php


$url = &#39;https://www.php.cn/user?id=PHP中文网&#39;;


/**
 * 编码
 * @var string
 */
$url = urlencode($url);

/**
 * 解码
 * @var string
 */
$url = urldecode($url);

Recommended tutorial: "PHP"

The above is the detailed content of How to transcode Chinese in URL with PHP?. 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