Home >Backend Development >PHP Problem >How to convert php Chinese to url encoding
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.
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 '<a href="w3cschool?foo='. urlencode($str). '">'; ?>
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!