In this tutorial we will show you how to encode and decode url using PHP. Encoding and decoding is required before sending and after sending the url to replace some special characters from url.
CHECK OUT THIS TUTORIAL LIVE DEMO →
To Encode And Decode URL It Takes Only Three Steps:-
- Make a HTML file and define markup
- Make a PHP file to encode and decode url
- Make a CSS file and define styling
Step 1. Make a HTML file and define markup
We make a HTML file and save it with a name url.html
<html> <head> <link href="url_style.css" type="text/css" rel="stylesheet"/> </head> <body> <div id="wrapper"> <div id="url_div"> <form method="post" action="encode_decode.php"> <input type="text" name="url" placeholder="Enter URL To Encode"> <input type="submit" name="encode_url" value="ENCODE"> </form> <form method="post" action="encode_decode.php"> <input type="text" name="url" placeholder="Enter URL To Decode"> <input type="submit" name="decode_url" value="DECODE"> </form> </div> </div> </body> </html>
In this step we create two forms one for to enter url for encoding and another is for url decoding and they send the url to 'encode_decode.php' page.
Step 2. Make a PHP file to encode and decode url
We make a PHP file and save it with a name encode_decode.php
<?php if(isset($_POST['encode_url'])) { $url = $_POST['url']; $encodedUrl = urlencode($url); $converted_url=$encodedUrl; } if(isset($_POST['decode_url'])) { $url = $_POST['url']; $decodedUrl = urldecode($url); $converted_url=$decodedUrl; } ?>
In this step we create two isset() conditions to encode and decode the urls. In first condition we get url value and encode url using php urlencode() function. In second condition we use urldecode() function to decode url.
Step 3. Make a CSS file and define styling
We make a CSS file and save it with a name url_style.css
body { margin:0 auto; padding:0px; text-align:center; width:100%; font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif; background-color:#D6EAF8; } #wrapper { margin:0 auto; padding:0px; text-align:center; width:995px; } #wrapper h1 { margin-top:50px; font-size:45px; color:#3498DB; } #wrapper h1 p { font-size:18px; } #url_div input[type="text"] { width:300px; height:35px; border:1px solid #AED6F1; padding-left:10px; font-size:17px; } #url_div input[type="submit"] { background-color:#3498DB; border:none; width:100px; height:35px; color:white; }
That's all, this is how to encode and decode url using PHP.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery