The Wayback Machine - https://web.archive.org/web/20231211192657/https://www.geeksforgeeks.org/php-rawurlencode-function/
Open In App
Related Articles

PHP | rawurlencode() function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The rawurlencode() function is an inbuilt function in PHP which is used to encode the URL(Uniform Resource Locator) according to RFC(Uniform Resource Identifier) 3986.

Syntax:

string rawurlencode( $str )

Parameters: This function accepts single parameters $str which is mandatory. It is used to store the URL which is to be encoded.

Return Value: This function returns a string which contains all non-alphanumeric characters except -_.~ symbols. The symbols or space character replaced with a percent (%) sign followed by two hex digits.

Below programs illustrate the rawurlencode() function in PHP.

Program 1:




<?php
echo '<a href="www.geeksforgeeks.org',
  rawurlencode('A computer science portal for geek'), '">';
?>


Output:

<a href="www.geeksforgeeks.orgA%20computer%20science%20portal%20for%20geek">

Program 2:




<?php
  
// Store the URL string
$str = 'A computer science portal for geek';
  
// Encode the URL string and print it.
echo '<a href="www.geeksforgeeks.org', rawurlencode($str), '">';
?>


Output:

<a href="www.geeksforgeeks.orgA%20computer%20science%20portal%20for%20geek">

Related Articles:

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Aug, 2018
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials