Hongmu Notes

🧷 URL encoding and decoding

The encoding gives two writing methods at the same time, and the decoding restores the %XX content.

Instructions for use

  • Click "Encode" to get both encodeURI and encodeURIComponent results at the same time
  • Click "Decode" to restore %XX content using decodeURIComponent
  • "Content exchange" backfills the results into the input box, and a prompt will be given for illegal percent signs.

URL encoding and decoding

Convert characters such as Chinese and spaces into %XX to safely put them into links, and conversely, convert %XX into readable text.

📌 Is it normal that the link becomes longer after encoding?

Normal. After one Chinese character is encoded, there are three %XX fragments (three digits each), so the more Chinese links there are, the longer they are after encoding; this is the result of UTF-8 byte-by-byte encoding, not duplication or error.

📌 Coding rules

The encoding button is executed twice at the same time: once using encodeURI, retaining structural symbols such as colons, slashes, question marks, pound signs, square brackets, @ and &, etc., and only encoding characters such as spaces and Chinese; another time using encodeURIComponent, encoding structural symbols as well, so the result is more suitable as a parameter value. The decode button only calls decodeURIComponent. If it encounters an incomplete sequence of percent signs, a prompt will be given and the result will be cleared.

🧭 Common uses

It is common to assemble query links with Chinese characters or spaces, safely put user input into parameter values, check the encoded string returned by the backend, and troubleshoot problems such as "& in parameters are treated as delimiters." The two encoding results are given side by side, and the impact of structural symbols can be intuitively seen.

All keywords and tutorials 12

❓ FAQ

Can it handle the entire link?
Yes, just paste the entire link; it is recommended to use the result of encodeURI to retain the structural symbols.
Can decoding restore Chinese?
Yes, %E4%B8%AD%E6%96%87 will be restored to two Chinese characters.
URL encoding and decoding checkpoints
Only printable characters remain in the encoding result, and the decoding result is consistent with the original text word for word.