Ezilon.com - Target Your Audience, be Seen in Your Region

PHP: Talk to me Javascript!

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.
teammatt3's picture
Moderator

He has: 1,836 posts

Joined: Sep 2003

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's picture
Moderator

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.

Greg K's picture
Moderator

He has: 1,611 posts

Joined: Nov 2003

What are you needing it encoded for?

-Greg

teammatt3's picture
Moderator

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.