Home >Backend Development >PHP Problem >Usage of php urlencode function

Usage of php urlencode function

藏色散人
藏色散人Original
2021-03-05 10:27:042333browse

php The urlencode function is used to encode a string and use it in the request part of the URL. It also facilitates passing variables to the next page. Its usage syntax is "string urlencode(string $str)" , the parameter str represents the string to be encoded.

Usage of php urlencode function

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

urlencode() encoding 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 with variables matching 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">

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of Usage of php urlencode function. 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