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

How to convert php Chinese to url encoding

藏色散人
Release: 2023-03-03 21:12:01
Original
2182 people have browsed it

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 )
Copy after login

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;;
?>
Copy after login

The above code will output:

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

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!

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