PHP urlencode() Function Example to encode URL

Using PHP urlencode() Function Example tutorial you will learn how to encode given_url in PHP using the PHP urlencode() function with examples.

The urlencode() function is an inbuilt function in PHP which is used to encode the url. This function returns a string which consist all non-alphanumeric characters except -_. and replace by the percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

PHP urlencode() Function

The PHP urlencode() is an inbuilt function in PHP. That is used to encode the given URL. It will return an encoded string on success.


The basic syntax of php urlencode() function is following:

urldecode( $url )

Example urlencode function

Let’s take the first example of PHP encode URL. Here we have one url like “”, and we will encode using the PHP urlencode() function.

$url = "";
echo urlencode("$url") . "\n"; 


Example 2 : PHP URL encode Function

echo urlencode("") . "\n"; 
 echo urlencode("") . "\n";


I hope you enjoy with this example;

Leave a Comment