Home >Backend Development >PHP Problem >How to convert php Chinese to url encoding

How to convert php Chinese to url encoding

藏色散人
藏色散人Original
2020-08-06 09:47:032190browse

In PHP, you can use the urlencode function to encode the Chinese string in the URL to avoid errors in the URL call. The syntax is "string urlencode (string $str)", and the parameter "str" ​​represents the character to be encoded. string.

How to convert php Chinese to url encoding

Recommended: "PHP Video Tutorial"

PHP urlencode() function

Definition and usage

urlencode() encodes URL string 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.

We often use this function to encode Chinese strings in URLs to avoid errors in URL calls.

Related functions: urldecode() function, decoding URL string function.

Syntax

string urlencode ( string $str )

Parameters

str The string to be encoded

Note:

Note: Be careful Variables that match HTML entities. Characters like &, ©, and £ will all be parsed by the browser and replace the expected variable name with the actual entity. This is obvious confusion, and the W3C has been warning people about it for several years.

Example

<?php
$str = "w3cschool你好";
echo &#39;<a href="w3cschool?foo=&#39;. urlencode($str). &#39;">&#39;;
?>

The above code will output:

<a href="w3cschool?foo=w3cschool%E4%BD%A0%E5%A5%BD">

The above is the detailed content of How to convert php Chinese to url encoding. 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