php-i18n Digest 28 Apr 2007 19:21:04 -0000 Issue 354
Topics (messages 1059 through 1062):
Re: PHP and AJAX
1059 by: Anirudh Zala
1060 by: lazaros
1061 by: Anirudh Zala
PHP 6: Mysql with iso-8859-1 chars outputting utf-8: "Could not convert binary
string to Unicode string"
1062 by: Rangel Reale
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
On Thursday 12 April 2007 03:35, lazaros wrote:
> I have this code that sends some information to a php page that searches a
> database and returns the results. The code is:
>
> //showCustomer.js
> ...
>
> var url="showCustomer.php?flag="+flag
> url=url+"&initial="+str
> url=url+"&customer_radio="+customer_radio
> url=url+"&is_prospect="+is_prospect
>
> xmlHttp.onreadystatechange=stateChanged
> xmlHttp.open("GET",url,true)
> xmlHttp.send(null)
> ...
>
> //The php page(showCustomer.php)
> ...
> $initial = $_GET['initial'];
> ...
> $show_customer_query = mysql_query("SELECT * FROM customer WHERE
> customer_name LIKE '$initial%' ORDER BY customer_name");
> ...
>
> In Firefox works perfect both with english and greek.
> But when it comes to IE6 and 7 it works only with english. The $initial var
> is not passed to showCustomer.php properly,so the query fails. If I pass a
> letter α(like a) or σ(like s), $initial is something like this � or a
> square.This happens with all the greek letters.What is the problem?I don't
> mind working only with Firefox(I am working only with it), but what about
> the other users?...
> Everything is UTF8. And the problem appears when I send through GET the
> parameters.
>
> --
> View this message in context:
> http://www.nabble.com/PHP-and-AJAX-tf3562272.html#a9949352 Sent from the
> Php - Internationalization (i18n) mailing list archive at Nabble.com.
You can try following ways.
1: Try to echo (alert) value of "str" before querying using Ajax to make sure
that JS engine in IE handles it properly before sending back to server.
2: Set default encoding of browser as "utf-8".
3: Try to set character set as "utf-8" in JS if it is possible.
4: Try to use utf_encode() and utf_decode() like functions to encode/decode
string before sending to PHP.
Let me know what happens, we will test more ways if one or more of these
doesn't work.
Anirudh Zala
--- End Message ---
--- Begin Message ---
Thank you very much for the reply.
I have been working with this problem for a while with a co-worker in the
company that I work. The conclusion is that IE is here to make our work
harder :). When the $_GET value was send to the php page, Firefox handled it
right because it can do utf encoding(am I right?),but IE can't.So what we
had to do is to encode the value before it was sent to php. So in
showCustomer.js we added this simple line:
var url="showCustomer.php?flag="+flag
url=url+"&initial="+str
url=url+"&customer_radio="+customer_radio
url=url+"&is_prospect="+is_prospect
url = encodeURI(url) //---->That's the new line we have added
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
I can't say if this is the right way to deal with that thing, but it works
fine.Anyway Anirudh thanks for the reply.I think you were also on the right
way :)))
--
View this message in context:
http://www.nabble.com/PHP-and-AJAX-tf3562272.html#a9970283
Sent from the Php - Internationalization (i18n) mailing list archive at
Nabble.com.
--- End Message ---
--- Begin Message ---
On Friday 13 April 2007 04:47, lazaros wrote:
> Thank you very much for the reply.
> I have been working with this problem for a while with a co-worker in the
> company that I work. The conclusion is that IE is here to make our work
> harder :). When the $_GET value was send to the php page, Firefox handled
> it right because it can do utf encoding(am I right?),but IE can't.So what
> we had to do is to encode the value before it was sent to php. So in
> showCustomer.js we added this simple line:
>
> var url="showCustomer.php?flag="+flag
> url=url+"&initial="+str
> url=url+"&customer_radio="+customer_radio
> url=url+"&is_prospect="+is_prospect
> url = encodeURI(url) //---->That's the new line we have added
This is perfect also. But here you would get benefit for local application
only. To get advantage in all applications, try to find global solution like
setting character set or encoding directly in JS or telling Ajax engine to
encode every URL before submitting to server etc.
>
> xmlHttp.onreadystatechange=stateChanged
> xmlHttp.open("GET",url,true)
> xmlHttp.send(null)
>
> I can't say if this is the right way to deal with that thing, but it works
> fine.Anyway Anirudh thanks for the reply.I think you were also on the right
> way :)))
> --
> View this message in context:
> http://www.nabble.com/PHP-and-AJAX-tf3562272.html#a9970283 Sent from the
> Php - Internationalization (i18n) mailing list archive at Nabble.com.
Anirudh Zala
--- End Message ---
--- Begin Message ---
Hello!
I have a MySQL database where all tables are in the latin1 character set, with
accented (Portuguese) characters.
In my php.ini I have
;;;;;;;;;;;;;;;;;;;;
; Unicode settings ;
;;;;;;;;;;;;;;;;;;;;
unicode.semantics = on
unicode.runtime_encoding = iso-8859-1
unicode.script_encoding = iso-8859-1
unicode.output_encoding = utf-8
unicode.from_error_mode = U_INVALID_SUBSTITUTE
unicode.from_error_subst_char = 3f
unicode.fallback_encoding = iso-8859-1
because all my files and data in mysql server are in iso-8859-1.
When connecting to mysql I issue:
mysql_query('set names latin1', $this->mysql_link);
but when I do query in any record that have accented characters I get this
warning (using mysql_fetch_assoc):
----------
Could not convert binary string to Unicode string (converter UTF-8 failed on
bytes (0xE7) at offset 9)
----------
for all accented characters in all fields.
If I changed the set names query to:
mysql_query('set names utf8', $this->mysql_link);
it works, but I would like to keep compatibility with PHP 5, and for my
application it requires set names to be latin1. Also, my databases are not
created with the "utf8" option.
As I understood PHP 6's unicode support, all string characters (including mysql
result values) are converted from unicode.runtime_encoding to unicode (utf-16),
but looks like it is trying to convert from ASCII, which does not have all the
accented characters. Am I assuming right? How to make mysql_fetch_assoc assume
field values are in iso-8859-1 instead of ASCII?
Thanks,
Rangel Reale
--- End Message ---