So I have a textarea on a page. When a user clicks the submit button, Javascript grabs the content in the textarea and sends it off to a PHP file using an XMLHttpRequest object. How can I, using Javascript, encode the content in the textbox, and then decode it on the PHP page?
Is there a decode/encode function that works in JS and PHP? I've tried quite a few functions, and I'm not having much luck!






teammatt3 posted this at 20:48—27th May 2008.
He has: 1,836 posts
Joined: Sep 2003
According to some commenter on the PHP doc pages, JS's encodeURIComponent and PHP's rawurlencode perform the same type of encoding. So I can use encodeURIComponent in Javascript and rawurldecode in PHP.
My Site | Regular Expression Tester
Greg K posted this at 05:35—28th May 2008.
He has: 1,611 posts
Joined: Nov 2003
What are you needing it encoded for?
-Greg
teammatt3 posted this at 16:36—28th May 2008.
He has: 1,836 posts
Joined: Sep 2003
Because if someone enters "this is some text and this could through off the program &some_param=hahahah4" and it's not encoded, it could throw off the PHP script. It's not necessarily a security risk for my program, but it could produce some unexpected output for the user, which I want to avoid.
My Site | Regular Expression Tester