Home > Article > Backend Development > How to use urlencode() function for url encoding in PHP? (code example)
The urlencode() function is a built-in function in PHP used to encode urls. The following article will introduce to you some usage of the urlencode() function, so that you can understand how the urlencode() function encodes URLs. I hope it will be helpful to you.
[Video tutorial recommendation: PHP tutorial]
## The urlencode() function accepts a url as a parameter and returns a string. All non-alphanumeric characters contained in this string, except -_., are replaced with a percent sign (%) followed by two hexadecimal digits, and spaces are encoded as plus signs ( ).Recommended manual:php complete self-study manual
Basic syntax
string urldecode( $input )
Parameters :This function accepts a single parameter $input, which holds the url to be encoded.
Return value: The urlencode() function successfully returns the encoded string.
Let’s take a look at how the PHP urlencode() function encodes URLs through code examples.Example 1:
<?php echo urlencode("PHP:s? hg+3\c=67 "); ?>Output:
PHP%3As%3F+hg%2B3%5Cc%3D67+
Example 2:
<?php echo urlencode("http://www.php.cn/") . "<br>"; echo urlencode("http://www.baidu.com/?tn=62095104_26_oem_dg") . "<br>"; ?>Output:
http%3A%2F%2Fwww.php.cn%2F http%3A%2F%2Fwww.baidu.com%2F%3Ftn%3D62095104_26_oem_dg
Recommended related articles: 1.The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
How does PHP encode and decode Chinese characters in Url? (Pictures and videos)
Related video recommendations: 1.
Dugu Jiujian (4)_PHP video tutorial
The above is the detailed content of How to use urlencode() function for url encoding in PHP? (code example). For more information, please follow other related articles on the PHP Chinese website!