Friday, October 10, 2025
HomeLanguagesPHP | rawurlencode() function

PHP | rawurlencode() function

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.neveropen.techA%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.neveropen.techA%20computer%20science%20portal%20for%20geek">

Related Articles:

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

RELATED ARTICLES

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6717 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6792 POSTS0 COMMENTS