การเข้ารหัส
URL Encode/Decode
เข้ารหัสและถอดรหัส URL — อักขระที่ต้อง escape ในลิงก์และพารามิเตอร์ของ query
URL encoding (percent-encoding) replaces characters that aren't allowed in a URL — spaces, non-Latin letters, special characters — with %XX sequences, where XX is the hex code of the byte. This keeps links and query parameters from getting mangled in transit.
How to use it
- Encode: paste text or a URL and any character outside the safe ASCII set is replaced with a %XX sequence.
- Decode: paste an encoded string to see the original text.
- Encoding a full URL and encoding a single query parameter use slightly different safe-character sets — pick the mode that matches what you're encoding.
Common uses
- Building query parameters from text containing spaces, ampersands, or non-Latin characters.
- Debugging why a link with a parameter breaks — often the cause is an unencoded special character.
- Decoding URLs from third-party systems to read them in their original form.
Things to keep in mind
Encode parameter values, not the whole URL at once — otherwise you'll also encode the separators you need (:, /, ?, &).
JavaScript's encodeURIComponent and encodeURI encode different character sets — the former is meant specifically for parameter values.
บทความเกี่ยวกับเครื่องมือนี้: URL Encode/Decode: percent-encoding ในลิงก์
คำถามที่พบบ่อย
การเข้ารหัสแบบ Component กับ URI ต่างกันอย่างไร?
การเข้ารหัส Component (encodeURIComponent) หลีกอักขระสงวนเกือบทั้งหมด จึงเหมาะกับพารามิเตอร์คำค้นหรือส่วนของเส้นทางเดี่ยว ๆ ส่วนการเข้ารหัส URI (encodeURI) จะไม่แตะอักขระอย่าง / : ? & = เพราะออกแบบมาสำหรับเข้ารหัส URL ทั้งเส้นที่มีโครงสร้างอยู่แล้ว
การเข้ารหัส URL เหมือนกับ Base64 หรือไม่?
ไม่ ทั้งสองมักถูกเข้าใจผิดว่าเหมือนกันแต่เป็นเทคนิคที่ต่างกัน การเข้ารหัส URL (percent-encoding) แทนที่อักขระที่ไม่ปลอดภัยด้วยลำดับ %XX และคงข้อความ ASCII ส่วนใหญ่ให้อ่านได้ ในขณะที่ Base64 เข้ารหัสข้อมูลทั้งหมดใหม่ด้วยชุดอักขระที่กระชับ — คุณจะใช้ Base64 แบบ URL-safe เพื่อจุดประสงค์อื่น เช่น ฝังข้อมูลไบนารีลงใน URL
เครื่องมือนี้ส่ง URL ของฉันไปยังเซิร์ฟเวอร์หรือไม่?
ไม่ การเข้ารหัสและถอดรหัสทำงานทั้งหมดในเบราว์เซอร์ของคุณ ดังนั้นสิ่งที่คุณวางที่นี่จะไม่ถูกส่งไปที่ใดเลย
การเข้ารหัสซ้อนสองชั้นคืออะไร และสังเกตได้อย่างไร?
เป็นข้อผิดพลาดที่เกิดจากการเข้ารหัสสตริงที่ถูกเข้ารหัสไปแล้วซ้ำอีกครั้ง — สัญลักษณ์ % จะถูกแปลงเป็น %25 เอง ทำให้ %20 กลายเป็น %2520 สัญญาณของปัญหานี้คือลำดับอักขระแบบ %25XX ในผลลัพธ์ที่ถอดรหัสแล้ว
ทำไมช่องว่างบางครั้งถูกเข้ารหัสเป็น + และบางครั้งเป็น %20?
+ สำหรับช่องว่างเป็นรูปแบบของ application/x-www-form-urlencoded ที่ฟอร์มและ query string ใช้ ส่วน %20 คือ percent-encoding มาตรฐานตาม RFC 3986 ซึ่งถูกต้องในทุกส่วนของ URL