Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Pablo Viquez' Blog:
How to use json_encode with ISO-8859-1 data – Part2
Aug 03, 2009 @ 12:57:10

As he mentioned in a previous entry on his blog, Pablo Viquez found a few issues with character encoding and the json_encode function. He revisits this in a second look at getting it to cooperate with ISO-8859-1 data.

One solution that I did, in order to preserve the character set was to encode the data before using the json_encode function to use just A-Z, a-z and 0-9 characters, instead of sending text with accents or symbols. One encoding that fits perfectly in this schema, is Base64 Content-Transfer-Encoding. (see base 64 explanation below) This leads me to the solution: Encode the ISO-8859-1 using base64 and decoded in the client using JavaScript.

He includes both a code example for his solution and downloadable code for you to try it out yourself.

tagged: jsonencode iso88591 javascript tutorial

Link:

Pablo Viquez's Blog:
JSON, ISO 8859-1 and UTF-8 - Part
Jul 20, 2009 @ 17:42:36

After spotting some null values in a few of his form fields following an Ajax request, Pablo Viquez decided to track down his issue:

While I was looking at some AJAX calls, I started to have a problem, for some reason, when I tried to query a JSON service I did using JQuery, the result was null for some fields. Going a little deeper, I notice that the records from the DB were OK, and the JavaScript was OK to, so what was the problem? The JSON Encode!

His issue stemmed from the character encoding of the string being passed into json_encode (in this case, UTF-8) was coming from a PHP script saved in a page encoded as ISO-8859-1. You can download the files he's come up with to illustrate the point.

tagged: json encode utf8 iso88591 jsonencode

Link:


Trending Topics: