Get Url Encode / Decode Online code snippets for PHP, JAVA, Python, C# and Visual Basic, just copy and paste the code in your project
// Function to URL encode a string
function custom_url_encode($url) {
return urlencode($url);
}
// Function to URL decode a string
function custom_url_decode($url) {
return urldecode($url);
}
// Example usage
$url = "https://example.com/page with spaces";
$encoded_url = custom_url_encode($url);
$decoded_url = custom_url_decode($encoded_url);
echo "Encoded URL: " . $encoded_url . " ";
echo "Decoded URL: " . $decoded_url . " ";
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class URLEncodeDecode {
// Function to URL encode a string
public static String customUrlEncode(String url) {
try {
return URLEncoder.encode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
// Handle encoding exception
e.printStackTrace();
return null;
}
}
// Function to URL decode a string
public static String customUrlDecode(String url) {
try {
return URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
// Handle decoding exception
e.printStackTrace();
return null;
}
}
// Example usage
public static void main(String[] args) {
String url = "https://example.com/page with spaces";
String encodedUrl = customUrlEncode(url);
String decodedUrl = customUrlDecode(encodedUrl);
System.out.println("Encoded URL: " + encodedUrl);
System.out.println("Decoded URL: " + decodedUrl);
}
}
import urllib.parse
# Function to URL encode a string
def custom_url_encode(url):
return urllib.parse.quote(url)
# Function to URL decode a string
def custom_url_decode(url):
return urllib.parse.unquote(url)
# Example usage
url = "https://example.com/page with spaces"
encoded_url = custom_url_encode(url)
decoded_url = custom_url_decode(encoded_url)
print("Encoded URL:", encoded_url)
print("Decoded URL:", decoded_url)
using System;
using System.Web;
class Program
{
// Function to URL encode a string
static string CustomUrlEncode(string url)
{
return HttpUtility.UrlEncode(url);
}
// Function to URL decode a string
static string CustomUrlDecode(string url)
{
return HttpUtility.UrlDecode(url);
}
// Example usage
static void Main(string[] args)
{
string url = "https://example.com/page with spaces";
string encodedUrl = CustomUrlEncode(url);
string decodedUrl = CustomUrlDecode(encodedUrl);
Console.WriteLine("Encoded URL: " + encodedUrl);
Console.WriteLine("Decoded URL: " + decodedUrl);
}
}
Imports System
Imports System.Web
Module Program
' Function to URL encode a string
Function CustomUrlEncode(ByVal url As String) As String
Return HttpUtility.UrlEncode(url)
End Function
' Function to URL decode a string
Function CustomUrlDecode(ByVal url As String) As String
Return HttpUtility.UrlDecode(url)
End Function
' Example usage
Sub Main(args As String())
Dim url As String = "https://example.com/page with spaces"
Dim encodedUrl As String = CustomUrlEncode(url)
Dim decodedUrl As String = CustomUrlDecode(encodedUrl)
Console.WriteLine("Encoded URL: " & encodedUrl)
Console.WriteLine("Decoded URL: " & decodedUrl)
End Sub
End Module
URL Encoding and Decoding are essential processes in programming languages like JavaScript and Python. In high school, you might learn that URLs contain special characters like spaces or symbols, but computers prefer simpler formats. URL Encoding solves this problem by converting these special characters into a format that computers can understand. For example, a space might become "%20", making it easier for computers to process.
On the other hand, URL Decoding does the reverse—it converts these encoded characters back into their original form. This is crucial when a program needs to interpret data from a URL. For instance, if a website wants to display a message with spaces in the URL, decoding helps the computer understand those spaces properly. In both encoding and decoding, the goal is to ensure that data can be accurately transmitted and understood by computers across different platforms and languages.