From: Christoph Boget on
I'm curious if the behavior of json_encode() is influenced by the
browser at all. I have a page that returns search results. If I
access the page and perform a search using Chrome, the following error
shows up in the log:

PHP Warning: json_encode() [<a
href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8
sequence in argument in [PAGE] on line [LINE]

If I access the page and perform a search, the exact same search using
the exact same parameters, using Firefox then I get the expected
results. When I var_dump() the return value of json_encode(), I see
that it is a null in the case where I accessed using chrome but the
expected string in the case where I accessed using firefox. In both
cases, the input array is identical.

Given the identical input and different output, the only thing I can
figure is that the headers sent to the server as part of the request
figure in to how json_encode() behaves. Is that the case? Or am I
barking up the wrong tree?

To be clear, I'm not talking about how the browser ultimately handles
the json encoded data. I know there can be issues with that. I'm
talking about the process before the data is even shipped to the
browser -- about how json_encode() behaves when executed as part of
the PHP script.

thnx,
Christoph
From: "Jo�o C�ndido de Souza Neto" on
It can have something to do with your browser codification (UTF8,
ISO-8859-???).

--
Jo�o C�ndido de Souza Neto

"Christoph Boget" <cboget(a)hotmail.com> escreveu na mensagem
news:AANLkTi=45-HEtO2MYhQ116GV6bfxvDBA_yXfzJNqKVV8(a)mail.gmail.com...
> I'm curious if the behavior of json_encode() is influenced by the
> browser at all. I have a page that returns search results. If I
> access the page and perform a search using Chrome, the following error
> shows up in the log:
>
> PHP Warning: json_encode() [<a
> href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8
> sequence in argument in [PAGE] on line [LINE]
>
> If I access the page and perform a search, the exact same search using
> the exact same parameters, using Firefox then I get the expected
> results. When I var_dump() the return value of json_encode(), I see
> that it is a null in the case where I accessed using chrome but the
> expected string in the case where I accessed using firefox. In both
> cases, the input array is identical.
>
> Given the identical input and different output, the only thing I can
> figure is that the headers sent to the server as part of the request
> figure in to how json_encode() behaves. Is that the case? Or am I
> barking up the wrong tree?
>
> To be clear, I'm not talking about how the browser ultimately handles
> the json encoded data. I know there can be issues with that. I'm
> talking about the process before the data is even shipped to the
> browser -- about how json_encode() behaves when executed as part of
> the PHP script.
>
> thnx,
> Christoph


From: =?ISO-8859-1?Q?Jo=E3o_Souza?= on
You should set the charset of your page by meta tag in its head.


2010/9/1 Christoph Boget <christoph.boget(a)gmail.com>

> > It can have something to do with your browser codification (UTF8,
> > ISO-8859-???).
>
> But why would that be the case? Is json_encode() actually encoding
> the string differently in each case? And would it encode it
> differently if I wrote a script to take the same input and ran it from
> the command line?
>
> Is there a way I can get around this on the back end? Make it so that
> it'll behave the same in all cases?
>
> thnx,
> Christoph
>



--
João Cândido de Souza Neto
From: Christoph Boget on
> It can have something to do with your browser codification (UTF8,
> ISO-8859-???).

But why would that be the case? Is json_encode() actually encoding
the string differently in each case? And would it encode it
differently if I wrote a script to take the same input and ran it from
the command line?

Is there a way I can get around this on the back end? Make it so that
it'll behave the same in all cases?

thnx,
Christoph
From: Christoph Boget on
> You should set the charset of your page by meta tag in its head.

Do you have a source of reference to which you point me?

thnx,
Christoph