The urlencode() function is an inbuilt PHP function used to encode the URL.
This function returns a string consisting of all non-alphanumeric characters except—_. It is replaced by the percent (%) sign, followed by two hex digits and spaces encoded as plus (+) signs.
Syntax:
string urlencode( $input )Parameters:
This function accepts single parameter $input which is used to hold the url to be encoded.
Return Value:
This function returns an encoded string on success. Below programs illustrate the urlencode() function in PHP:
Example 1: This example shows the implementation of PHP urlencode() Function.
<?php
// PHP program to illustrate urlencode function
echo urlencode("https://www.geeksforgeeks.org/") . "\n";
?>
Output
https%3A%2F%2Fgeeksforgeeks.org%2F
Example 2: This example shows the implementation of PHP urlencode() Function.
<?php
// PHP program to illustrate urlencode function
echo urlencode("https://write.geeksforgeeks.org/") . "\n";
echo urlencode("https://www.geeksforgeeks.org/") . "\n";
echo urlencode("https://www.geeksforgeeks.org/") . "\n";
?>
Output
https%3A%2F%2Fwrite.geeksforgeeks.org%2F https%3A%2F%2Fpractice.geeksforgeeks.org%2F https%3A%2F%2Fgeeksforgeeks.org%2F
PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.