2

I'm building an iOS app which among other things, sends data to a PHP server.

I have problems with accented characters like in the string jeremyö which when sent from:

  • iOS (using ASIHTTPRequest) is detected by PHP var_dump as string(7) "jeremyö"
  • from Firefox or Chrome is detected by PHP var_dump as string(8) "jeremyö"

When used as a login, this breaks all my stuff.

Do you have any hint on how I can work around this behavior?

PHP part is UTF-8 only (Drupal 7 backend), and I don't know the encoding used on iOS, but I guess it's UTF-8 or maybe UTF-16.

Thanks, Jérémy

jchatard
  • 1,881
  • 2
  • 20
  • 25

1 Answers1

1

This sounds more like unicode canonicalization then encoding. In unicode a character like ö can be represented in two ways. It can be U+00F6 (small o with diaeresis) or it can be two characters: a normal o and a combining diaeresis (U+0308).

On iOS there are methods such as NSString's precomposedStringWithCanonicalMapping, decomposedStringWithCanonicalMapping etc that allow you to convert strings between these various representations, there are probably similar methods in php.

If you are using these strings as query parameters to your database then your database probably has settings that control what string equality means (for mysql it's the collation property)

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
  • Thank for this explanation. Unfortunately I'm stuck with supporting PHP 5.2 which doesn't have the Normalizer class http://php.net/manual/fr/normalizer.normalize.php – jchatard Jan 05 '12 at 09:16
  • You may be able to get away with doing the normalisation on the iPhone side, and do check your database collation settings - you may be able to dodge the php issue entirely – Frederick Cheung Jan 05 '12 at 09:25
  • I did try on the iOS side, but with no luck. And I can't handle all MySQL database since my app is for all Drupal users :-) – jchatard Jan 05 '12 at 17:02