Do you have a source of reference to which you point me?
thnx,
Christoph
I hope it can help you.
PS: json_decode works only in utf8.
--
João Cândido de Souza Neto
"Christoph Boget" <cbo...@hotmail.com> escreveu na mensagem
news:AANLkTikPQDCkRQ7ctjwCC...@mail.gmail.com...
I understand charsets. I understand the difference between the
charsets. What I don't understand is how json_encode() is taking the
*exact same input* and behaving differently (breaking in one case,
working in another) depending on the browser being used. And taking
your statement that json_encode() works only in utf-8 as a given, how
can I guard against the different behaviors on the backend, where
json_encode() is getting executed. Should I do some kind of header
sniffing prior to every call to json_encode() and massage the data
accordingly depending on what I find? That seems somewhat excessive.
But based on what you are saying and based on what I'm witnessing, it
seems like there is no other way around that.
thnx,
Christoph
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
2010/9/1 Christoph Boget <christo...@gmail.com>
--
If not, its using the charset set in your browser, which can be different
from one to another.
In this case, you must set if via meta tag to avoid it.
--
João Cândido de Souza Neto
"Christoph Boget" <cbo...@hotmail.com> escreveu na mensagem
news:AANLkTimbfbgUnifhThZTP...@mail.gmail.com...
You´ll need a more detailed debug so you can see excatly what´s happening.
--
João Cândido de Souza Neto
"Christoph Boget" <cbo...@hotmail.com> escreveu na mensagem
news:AANLkTikcTht0nXz1hi0EzJ=i2M3716Wepd=DepP...@mail.gmail.com...
>> Sorry about the error:
>> In this case, you must set IT via meta tag to avoid it.
>
> Ok, let's try this using a different approach. Consider the following
> pseudo-code:
>
> <?php
> $result = mysql_query( 'SELECT name, date FROM table WHERE field =
> "value"' );
> $array = array();
> while( $row = mysql_fetch_assoc( $result ))
> {
> $array[] = $row;
> }
>
> $string = json_encode( $array );
> ?>
>
> Why does the charset of the browser matter one whit to the value of
> either $row['name'] or $row['date'] such that it would break
> json_encode() in one case and not the other. Is it that PHP is taking
> the string which is returned as part of the result set and encoding it
> to match the charset passed in from the browser?
>
> thnx,
> Christoph
>
> * Disclaimer : the actual code (and data repository) I am using is
> slightly different from the above but is similar enough so that it's a
> valid representation
In this case, you must set IT via meta tag to avoid it.
--
João Cândido de Souza Neto
""João Cândido de Souza Neto"" <jo...@consultorweb.cnt.br> escreveu na
mensagem news:16.27.0741...@pb1.pair.com...
Ok, let's try this using a different approach. Consider the following
--
João Cândido de Souza Neto
"Christoph Boget" <cbo...@hotmail.com> escreveu na mensagem
news:AANLkTi=45-HEtO2MYhQ116GV6...@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