URL decode PHP with JS — Removing the Plus Sign

PHP functions for creating and decipering URL-safe strings are urlencode and urldecode.

Javascript functions for creating and deciphering URL-safe strings are escape and unescape.

PHP’s urlencode replaces spaces with + and Javascript’s escape replaces spaces with %20. So if you are decocing a string from PHP with Javascript, you have to replace all the + in the string with spaces using the JS string.replace function. Since + is an operator in Javascript, it has to be escaped with a backslash ( \ ) for the function to execute without error. The g flag has to be included to replace all instances of occurance ( g = global):

string.replace ( /\+/g, ' ' );

Links

urlencode
urldecode
escape
unescape
string.replace