[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1565
  • Last Modified:

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?
0
mammouth
Asked:
mammouth
  • 4
  • 3
1 Solution
 
leakim971PluritechnicianCommented:
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

0
 
mammouthAuthor Commented:
Not it only seem to fail when someone add the & char into the textarea.

like "me & you"
0
 
mammouthAuthor Commented:
sorry: no "Not" but "now"
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
leakim971PluritechnicianCommented:
Try :


Javascript :
        var obj = new Object;
        obj.id  = 1;
        obj.txt = encodeURIComponent( $('txt').value );
        data = JSON.stringify(obj);

PHP Side :

        $obj = stripslashes( $_POST['obj'] );
        $obj = json_decode($obj, true);

Open in new window

0
 
leakim971PluritechnicianCommented:
Hello mammouth,

What's up? It don't work ?

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now