It seems the AMFPHP module for drupal is messing up strings as it sends them over to the client. I recently found this "bug" (and fixed it) when I was working on a Swedish site and needed correctly encoded unicode text.
As it turns out, AMFPHP (the Drupal module) tells AMFPHP (the framework) to convert the encoding of all strings, incorrectly assuming that the database content is encoded using ISO-8859-1. Of course, Drupal stores all data as UTF-8 and that is also the encoding that should be retained all the way through PHP, AMF, and into the Flash TextField on the client side.
Judging by the current rate of updates and contributions to the AMFPHP module (last checked into HEAD in April this year) we might have to wait for an official fix. In the meantime, luckily, we can fix it ourselves.
On lines 46 through 50 in amfphp.module (wrong line numbers below) is the code to initialize the AMFPHP framework. The fix is as easy as commenting out line 49, like so:
$gateway = new AmfphpGateway(); $gateway->setClassPath($servicesPath); $gateway->setClassMappingsPath($voPath); /* Don't decode, since Drupal default is already UTF-8 $gateway->setCharsetHandler("utf8_decode","ISO-8859-1","ISO-8859-1"); */ $gateway->setErrorHandling(E_ALL ^ E_NOTICE);
It would probably be safer to check in some way which encoding is being used in the database, but ignoring character set conversion entirely like this does the trick if we know that our databases are UTF-8 (as should always be the case with Drupal.)
Comments
Hi Richard, thanks for
Hi Richard,
thanks for posting this information. You saved my day :-)
The AMFPHP-Module was updated yesterday (6.x-1.0-beta1), but the problem still exists. I had to apply your trick to fixit.
Frank
hi, i'm having a problem when
hi,
i'm having a problem when i need to show a database htmltext in mx:Text.
My characters are appearing as "começar" instead of "começar".
i tried what you said and also this tip:
http://labs.boulevart.be/index.php/2008/12/04/php-and-utf-8-the-way-to-s...
because there's another call to
$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");
in gateway.php
even with editing this way i'm sting having problens with mysql-drupal6 and amfphp as a module.
do you have any ideia of what more i can try?
Hey Carlos, I don't know what
Hey Carlos,
I don't know what might be wrong. As you see, the characters appear right here in your comment. Are you sure that the data in the database is really stored as UTF-8, as a conversion from UTF-8 to UTF-8 (which is an odd tip by the way) when the source encoding is really something else is bound to mess things up.
Have you tried just commenting the setCharHandler() call out and not using it (as I describe in the blog article)? Cause if you have UTF-8 in the database, then you won't need to do any conversion. And if it's some other encoding that is used in the database (such as ISO-8859-1), you'll want to use that as the source in the setCharHandler() call.
Cheers
/R
Hi, I'm just posting an
Hi,
I'm just posting an answer about it...february i was having that problem because i'm using fckeditor and it was enconding all characters by javascript before insert into the database.
So, at that time, my local database was inserted by strange characters instead the rigth ones.
Now it's working fine, thanks for the tips.
Post new comment