Javascript encodeURIComponent doesn't encode single quotes

javascript

Solution

I'm not sure why you would want them to be encoded. If you only want to escape single quotes, you could use `.replace(/'/g, "%27")`. However, good references are:

- When are you supposed to use escape instead of encodeURI / encodeURIComponent?

- Comparing escape(), encodeURI(), and encodeURIComponent() at xkr.us

- Javascript Madness: Query String Parsing #Javascript Encode/Decode Functions

Problem

Try it out: ``` encodeURIComponent("'@#$%^&"); ``` If you try this out you will see all the special characters are encoded except for the single quote. What function can I use to encode ALL the characters and use PHP to decode them? Thanks.

Original source

Related problems