Skip to content
Related Articles

Related Articles

PHP | urlencode() Function
  • Last Updated : 30 Apr, 2020

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.

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:



Program 1:




<?php
  
// PHP program to illustrate urlencode function
echo urlencode("https://geeksforgeeks.org/") . "\n";
  
?>


Output:

https%3A%2F%2Fgeeksforgeeks.org%2F

Program 2 :




<?php
  
// PHP program to illustrate urlencode function
echo urlencode("https://ide.geeksforgeeks.org/") . "\n";
echo urlencode("https://contribute.geeksforgeeks.org/") . "\n";
echo urlencode("https://practice.geeksforgeeks.org/") . "\n";
echo urlencode("https://geeksforgeeks.org/") . "\n";
  
?>


Output:

https%3A%2F%2Fide.geeksforgeeks.org%2F
https%3A%2F%2Fcontribute.geeksforgeeks.org%2F
https%3A%2F%2Fpractice.geeksforgeeks.org%2F
https%3A%2F%2Fgeeksforgeeks.org%2F

Reference: http://php.net/manual/en/function.urlencode.php

My Personal Notes arrow_drop_up
Recommended Articles
Page :