Re: [PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Andrew Burgess
Thanks guys; I've got it working now!

On Tue, Dec 15, 2009 at 9:54 AM, Wouter van Vliet / Interpotential
 wrote:
>>
>> If you don't have access to do this, look at stripslashes()
>
> And if you absolutely want to be on the safe side - check* if the
> magic_quotes option is enabled - if so; do stripslashes. If not - then
> obviously don't.
> * http://www.php.net/manual/en/function.get-magic-quotes-gpc.php
>
>>
>> --
>> Thanks!
>> -Shawn
>> http://www.spidean.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>
>
> --
> http://www.interpotential.com
> http://www.ilikealot.com
>
> Phone: +4520371433
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Wouter van Vliet / Interpotential
>
>
> If you don't have access to do this, look at stripslashes()
>

And if you absolutely want to be on the safe side - check* if the
magic_quotes option is enabled - if so; do stripslashes. If not - then
obviously don't.

* http://www.php.net/manual/en/function.get-magic-quotes-gpc.php


>
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
http://www.interpotential.com
http://www.ilikealot.com

Phone: +4520371433


Re: [PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Shawn McKenzie
Ashley Sheridan wrote:
> On Tue, 2009-12-15 at 06:52 -0500, Andrew Burgess wrote:
> 
>> This seems like a pretty basic question, but it has me stumped.
>>
>> Here's my scenario: I'm using Douglas Crockford's JSON2.js to parse an
>> object in JavaScript, which I then pass to a PHP script to store in a
>> file. I use JSON.stringify() on the object, which logs to the console
>> as this:
>>
>> {"employees":{"data":{"John":{"fname":"John","lname":"Doe","city":"Toronto","country":"Canada"
>>
>> Then I use the jQuery POST function to send it to a PHP script. Before
>> doing anything with it in PHP, I log the received value to the
>> console, and this is what I get:
>>
>> {\"employees\":{\"data\":{\"John\":{\"fname\":\"John\",\"lname\":\"Doe\",\"city\":\"Toronto\",\"country\":\"Canada\"
>>
>> The problem is, when I call the script to retrieve this data from a
>> file, JSON.parse can't parse it because of the back-slashes. I'm
>> pretty sure my problem is on the PHP side (since it's fine coming out
>> of JS); what do I need to do to fix this? is a preg_replace enough?
>>
> 
> 
> Turn off magic quotes, as it looks like they are enabled on your server.
> You can turn them off from the .htaccess file if you don't have access
> to the php.ini
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 

If you don't have access to do this, look at stripslashes()


-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Ashley Sheridan
On Tue, 2009-12-15 at 06:52 -0500, Andrew Burgess wrote:

> This seems like a pretty basic question, but it has me stumped.
> 
> Here's my scenario: I'm using Douglas Crockford's JSON2.js to parse an
> object in JavaScript, which I then pass to a PHP script to store in a
> file. I use JSON.stringify() on the object, which logs to the console
> as this:
> 
> {"employees":{"data":{"John":{"fname":"John","lname":"Doe","city":"Toronto","country":"Canada"
> 
> Then I use the jQuery POST function to send it to a PHP script. Before
> doing anything with it in PHP, I log the received value to the
> console, and this is what I get:
> 
> {\"employees\":{\"data\":{\"John\":{\"fname\":\"John\",\"lname\":\"Doe\",\"city\":\"Toronto\",\"country\":\"Canada\"
> 
> The problem is, when I call the script to retrieve this data from a
> file, JSON.parse can't parse it because of the back-slashes. I'm
> pretty sure my problem is on the PHP side (since it's fine coming out
> of JS); what do I need to do to fix this? is a preg_replace enough?
> 


Turn off magic quotes, as it looks like they are enabled on your server.
You can turn them off from the .htaccess file if you don't have access
to the php.ini

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Parsing JSON; back-slash problem

2009-12-15 Thread Andrew Burgess
This seems like a pretty basic question, but it has me stumped.

Here's my scenario: I'm using Douglas Crockford's JSON2.js to parse an
object in JavaScript, which I then pass to a PHP script to store in a
file. I use JSON.stringify() on the object, which logs to the console
as this:

{"employees":{"data":{"John":{"fname":"John","lname":"Doe","city":"Toronto","country":"Canada"

Then I use the jQuery POST function to send it to a PHP script. Before
doing anything with it in PHP, I log the received value to the
console, and this is what I get:

{\"employees\":{\"data\":{\"John\":{\"fname\":\"John\",\"lname\":\"Doe\",\"city\":\"Toronto\",\"country\":\"Canada\"

The problem is, when I call the script to retrieve this data from a
file, JSON.parse can't parse it because of the back-slashes. I'm
pretty sure my problem is on the PHP side (since it's fine coming out
of JS); what do I need to do to fix this? is a preg_replace enough?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php