URL एन्कोडिंग और डीकोडिंग

URL स्ट्रिंग को एन्कोड और डीकोड करें, विशेष वर्णों और गैर-ASCII पाठ को सुरक्षित रूप से प्रबंधित करें, जो क्वेरी पैरामीटर और पथ ट्रांसमिशन के लिए उपयुक्त है।

एन्कोड करें

एन्कोडिंग मोड

डीकोड करें

उपयोग निर्देश

URL एन्कोडिंग विशेष वर्णों या गैर-ASCII पाठ को %XX फॉर्मेट में बदल देती है, ताकि URL में सुरक्षित रूप से ट्रांसमिट किया जा सके।
‘एन्कोड’ का उपयोग करके पाठ को URL के लिए सुरक्षित रूप (जैसे क्वेरी पैरामीटर) में बदलें।
‘डीकोड’ का उपयोग करके %XX अनुक्रम को मूल वर्णों में वापस लाएँ।
आम परिदृश्य: क्वेरी पैरामीटर, फॉर्म डेटा ट्रांसमिशन, API कॉल आदि का प्रबंधन।

त्वरित उदाहरण

मूल पाठ
https://example.com/search?q=你好世界&type=text
URL एन्कोडिंग
https://example.com/search?q=%E4%BD%A0%E5%A5%BD%E4%B8%96%E7%95%8C&type=text

विशेषताएँ

  • दो एन्कोडिंग मोड: encodeURIComponent और encodeURI
  • लचीली स्पेस प्रबंधन: + या %20 के रूप में एन्कोड करें
  • वास्तविक समय में रूपांतरण और इनपुट/आउटपुट लंबाई सांख्यिकी प्रदर्शित करें
  • कॉपी/साफ़ करें बटन और द्विदिशीय भेजें विकल्प
  • पूर्ण अंतर्राष्ट्रीयकरण और DaisyUI बहु-थीम समर्थन

URL एन्कोडिंग क्या है

URL एन्कोडिंग वर्णों को %XX प्रतिशत-एन्कोडेड सीक्वेंस में बदलती है, ताकि URL में सुरक्षित रूप से भेजा जा सके।

encodeURIComponent अकेले घटक (जैसे एकल क्वेरी पैरामीटर मान) के लिए उपयुक्त है, यह अधिकांश अक्षर-संख्यात्मक नहीं होने वाले वर्णों को एन्कोड करता है।

encodeURI पूरे URI स्ट्रिंग के लिए उपयुक्त है, और ?, &, =, / जैसे संरचनात्मक अर्थ वाले आरक्षित वर्णों को एन्कोड नहीं करता।

आम उपयोग

  • क्वेरी पैरामीटर बनाना (खोज शब्द, फ़िल्टर शर्तें आदि)
  • GET/POST फॉर्म डेटा को एन्कोड करके भेजना
  • API अनुरोध पैरामीटर्स को एन्कोड करना
  • उपयोगकर्ता इनपुट को URL पथ खंड में सुरक्षित रूप से शामिल करना

आम प्रश्न और चुनौतियाँ

  • encodeURI vs encodeURIComponent: पैरामीटर के लिए component, पूरे URL के लिए URI
  • स्पेस और +: application/x-www-form-urlencoded में क्वेरी स्ट्रिंग में स्पेस को + के रूप में अक्सर इस्तेमाल किया जाता है
  • दोहरी डिकोडिंग से बचें: बार-बार डिकोड करने से डेटा खराब हो सकता है
  • अमान्य प्रतिशत अनुक्रम त्रुटि फेंकता है; अपवादों का सुंदर ढंग से उपचार करना आवश्यक है

प्रोग्रामिंग भाषाओं में URL एन्कोडिंग/डीकोडिंग कैसे करें

JavaScript
एन्कोड करें
// Component (recommended for query values)
const encoded = encodeURIComponent(text);
// If you need '+' for spaces in query strings
const encodedPlus = encoded.replace(/%20/g, '+');
// Full URI
const encodedUri = encodeURI(url);
डिकोड करें
// Treat '+' as space if needed
const input = plusAsSpace ? s.replace(/\+/g, ' ') : s;
// Component
const dec1 = decodeURIComponent(input);
// Fallback to decodeURI when input is a full URL
const dec2 = decodeURI(input);
PHP
एन्कोड करें
// Component (RFC 3986)
$encoded = rawurlencode($text);
// '+' for spaces (application/x-www-form-urlencoded)
$encodedPlus = str_replace('%20', '+', $encoded);
// Full query usage
$query = http_build_query(['q' => '你好 世界', 'type' => 'text']);
डिकोड करें
// Component
$decoded = rawurldecode($s);
// If input uses '+' for spaces
$decodedPlus = urldecode($s);
Python
एन्कोड करें
from urllib.parse import quote, quote_plus

# Component (RFC 3986)
enc = quote(text, safe='')
# '+' for spaces (application/x-www-form-urlencoded)
enc_plus = quote_plus(text)
डिकोड करें
from urllib.parse import unquote, unquote_plus

# Component
dec = unquote(s)
# Input with '+' for spaces
dec_plus = unquote_plus(s)
Go
एन्कोड करें
import (
    "net/url"
)

// Query component
enc := url.QueryEscape(text) // spaces => +
// Path segment
// go1.8+
// url.PathEscape(text)
डिकोड करें
import (
    "net/url"
)

// Query component
dec, _ := url.QueryUnescape(s)
// Path segment
// url.PathUnescape(s)
Rust
एन्कोड करें
// Cargo.toml: urlencoding = "^2"
use urlencoding::{encode, encode_binary};

let enc = encode(text);              // component; spaces => %20
let enc_plus = enc.replace("%20", "+"); // if you need '+' for spaces
डिकोड करें
use urlencoding::decode;

// decode treats '+' as space
let dec = decode(s)?; // Result, _>
Java
एन्कोड करें
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

// Query param / form style (spaces => '+')
String enc = URLEncoder.encode(text, StandardCharsets.UTF_8);
// For RFC3986-like component encoding, replace '+' with %20 if needed
String encSpace = enc.replace("+", "%20");
डिकोड करें
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

// URLDecoder treats '+' as space
String dec = URLDecoder.decode(s, StandardCharsets.UTF_8);