How to Encode and Decode url's Query Parameter in PHP

In this blog, you will learn how to encode and decode the query string or URL of a page.  In PHP we use query string to edit, delete data, or select data from a database by matching a particular column name.

So Professional developers use encode and decode functions to encode URL strings for special characters. There are some functions for encoding and decoding URLs as follows:

  • urlencode
  • base64_encode
  • urldecode
  • base64_decode


How to encode URL's query parameter

To encode url’s query parameter you can use both the methods together urlencode() and base64_encode().


Example:

<?php
 
$id=15;
 
$finalid=urlencode( base64_encode($id));
 
?>
 


Why encode URL's query parameter

Because URLs are limited to a number of characters like a digit, alphabets, and a few special characters like (-,_), etc, to use any other character we need encoding URL's query parameters.


How to decode URL's query parameter

To decode url’s query parameters we use urldecode() and base64_decode() function together.


Example:

<?php
 
$id="encoded string";
$finalid=base64_decode( urldecode( $id));
 
?>
 
 
Categories: web development php
Written By : Web Development Institute
Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing Expert Course

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 25 Days

Crash : 15 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 6 Months

Fastrack : 4 Months

Crash : 2 Months

Web Expert with Python

Regular : 12 Months

Fastrack : 6 Months

Crash : 3 Months

Related Blogs

Request For Demo