Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP equivalent for javascript escape/unescape

Let's say I have a string: something

When I escape it in JS I get this: %73%6F%6D%65%74%68%69%6E%67

so I can use this code in JS to decode it:

 document.write(unescape('%73%6F%6D%65%74%68%69%6E%67'));

I need the escape function in PHP which will do the same (will encode something to : %73%6F%6D%65%74%68%69%6E%67)

How to do that ?

like image 382
chubbyk Avatar asked Mar 20 '13 21:03

chubbyk


2 Answers

PHP:

rawurlencode("your funky string");

JS:

decodeURIComponent('your%20funky%20string');

Don't use escape as it is being deprecated.

like image 189
i-- Avatar answered Nov 05 '22 23:11

i--


rawurldecode('%73%6F%6D%65%74%68%69%6E%67');
like image 23
Roger Gajraj Avatar answered Nov 05 '22 23:11

Roger Gajraj