Home » HTML » HTML_AJAX » Bug #8540
Setting charset
Details
| Request #8540 | Setting charset |
|---|---|
| Submitted | 2006-08-23 08:32 UTC |
| From | piotr_wierzbowski at sevenet dot pl |
| Status | Wont fix |
| Package | HTML_AJAX |
| PHP Version | 5.1.4 |
| OS | Debian |
| Roadmaps | (Not assigned) |
Comments
[2006-08-23 08:32 UTC] piotr_wierzbowski at sevenet dot pl
Description:
------------
How can I set charset for everything in this package, it is UTF-8 and I need iso-8859-2
I would be greatfull if i could set default charset in one variable (or if it's possible already give me a sign - sorry there is no good api :( )
[2006-08-23 08:35 UTC] piotr_wierzbowski at sevenet dot pl
*no good api desc. ;)
[2006-10-25 18:18 UTC] jeichorn at php dot net
the JSON serialization only works in utf-8 or ascii, are you thinking for non JSON requests or something else
[2006-10-25 19:28 UTC] jeichorn at php dot net
Also where do you want to set the Charset and want do you want that to do. Change the charset header, auto transcode using mbstring, something else.
[2006-10-27 07:51 UTC] piotr_wierzbowski at sevenet dot pl
For example: I have form with select list and serch filter as text field, i'm typeing into text field something and browser generates AJAX request witch changes my select list, it works completely fine, select list is changed, but options are in wrong charset, although when I return it manualy using ex. print_r they are right. When they are send using AJAX, they have wrong encoding. It would be fine if I could set text encoding witch is returned to browser. It could be set in dispatcher, maybe.
[2006-10-27 18:40 UTC] jeichorn at php dot net
If the data in question is being moved using JSON then encoding besides utf8 aren't an option
[2006-10-30 08:36 UTC] piotr_wierzbowski at sevenet dot pl
So how can i set something different than JSON witch can handle ISO-8859-2
[2006-11-11 15:17 UTC] raita at pambu dot com
Hey, I have kind of the same problem.
I use js:
HTML_AJAX.replace('browser', 'users.php');
and in the users-file I use swedish letters å ä and ö. But they get garbled up to chars like: � when loaded with ajax.
What to do?
Kind regards,
raita
[2006-11-21 14:53 UTC] auroraeosrose at php dot net
XmlHttpRequest uses the JSON serializer by default (the HTML_AJAX_Action class uses JSON as well). Unless you use a different serializer such as XML to pass the data you MUST deal with UTF-8 encoded data. This is a technical limitation of JSON and javascript, not HTML_AJAX. That means if you send data from PHP which is not UTF-8 it will be garbled. Right now HTML_AJAX assumes you are using UTF-8 and adds that to the content-type http header that is sent with the returned data.
Currently there are four serializers for HTML_AJAX, JSON, PHP, XML, and URLencoded. The examples directory has scripts using all of them. Although JSON must use UTF-8, it would be possible to add a "change charset" option for the xml serializer that could send the appropriate charset header when sending the data, and when creating the request sendig any get/post data correctly. However you'd still be responsible for
1. Making sure the data you send from PHP is in the right charset.
2. Setting headers for the initial page so the browser has the right charset.
3. Dealing with the data returned from the xmlhttprequest, you'd have to write javascript to deal with it
Probably the easiest solution is simply to use UTF-8 for your webpage. It would be less of a headache to use iconv or mbstring to transcode your current data to utf-8 before sending it, and changing your current intital page charset to UTF-8.
raita - your question is totally different - you need to make sure the initial page charset you're sending matches the charset of the users.php file
The bottom line - If you'd like to have the XML serializer (and possibly urlencoded or php serializers) be able to set a charset, please ask, but JSON must use UTF-8
[2006-11-28 12:03 UTC] piotr_wierzbowski at sevenet dot pl
I found a solution: before returning data to Ajax I changed charset with mb_convert_encoding($value, "utf-8", "iso-8859-2");
and it works nice :]