note 97768 deleted from function.json-decode by danbrown
| From: | danbrown@php.net | Date: | Fri, 07 May 2010 12:34:02 +0000 |
| Subject: | note 97768 deleted from function.json-decode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169054@lists.php.net to get a copy of this message | ||
Note Submitter: Ariel Lothlorien of UberSoftech dot com
----
Example:
URL: foo.php?bar=["one", "two", "three"]
Problem {
Code: <?PHP print_r(json_decode($_GET['bar'])); ?>
Output:
Code: <?PHP echo $_GET['bar']; ?>
Output: [\"one\",\"two\",\"three\"]
}
Solution{
Code: <?PHP echo stripslashes($_GET['bar']); ?>
Output: ["one","two","three"]
Code: <?PHP print_r(json_decode(stripslashes($_GET['bar']))); ?>
Output:
Array
(
[0] => one
[1] => two
[2] => three
)
}
Explanation:
Make sure if you are getting your data in a form that php slashes out perform stripslashes on your
var.
Warning: Be sure you know where your data is coming from and what type of formatting is being used
so you can read it properly.
Warning 2: Using stripslashes on strings that are not slashed may have undesirable effects.
Mahalo,
Ariel
P.s. Hope this helps feel free to email me for help... (my first name at ubersoftech dot com)