Link to home
Start Free TrialLog in
Avatar of mammouth
mammouth

asked on

json_decode fron encodeURIComponent strignify error on %0A and %22 from textarea

im getting error on json_decode(url_decode($var)) when a value of the array $var contain $0A or %22.
on JS side:

var obj = new Object;
      obj.id  = 1;
      obj.txt = encodeURIComponent($('txt').value);

then i use YUI! Connect.asyncRequest to send data using strignify to php.
JSON.stringify(obj)


On php side i decode the string using:

$obj = json_decode(urldecode($_POST['obj']));

The $_POST['obj'] contain "%0A" for skipped line and %22 for " and this return error when im getting the value.

How can i resolve this?
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Hello mammouth,

Try :


Javascript :

var obj = new Object;
obj.id  = 1;
obj.txt = $('txt').value);
// 
JSON.stringify(obj)

PHP Side :

$obj = json_decode($_POST['obj']);

Open in new window

Avatar of mammouth
mammouth

ASKER

Not it only seem to fail when someone add the & char into the textarea.

like "me & you"
sorry: no "Not" but "now"
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello mammouth,

What's up? It don't work ?

Regards.
No feedback ? :(
it work's if i encodeURIComponent obj and not only obj.txt