如何修复 2 个 Web 客户端之间的字符串长度编码?
我正在构建一个 iOS 应用程序,其中包括将数据发送到 PHP 服务器。
我遇到了重音字符问题,例如字符串 jeremyö
中的重音字符,当从以下位置发送时:
- iOS(使用 ASIHTTPRequest)被 PHP var_dump 检测为
- 来自 Firefox 的
string(7) "jeremyö"
或者 Chrome 被 PHP var_dump 检测为string(8) "jeremyö"
当用作登录名时,这会破坏我的所有内容。
您对我如何解决此行为有任何提示吗?
PHP部分仅是UTF-8(Drupal 7后端),我不知道iOS上使用的编码,但我猜它是UTF-8或者可能是UTF-16。
谢谢, 杰里米
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来更像是 unicode 规范化而不是编码。在 unicode 中,像 ö 这样的字符可以用两种方式表示。它可以是
U+00F6
(带分音符的小 o),也可以是两个字符:普通 o 和组合分音符 (U+0308)。在 iOS 上,有一些方法,例如 NSString 的
precomposedStringWithCanonicalMapping
、decomposedStringWithCanonicalMapping
等,允许您在这些不同的表示形式之间转换字符串,在 php.ini 中可能也有类似的方法。如果您使用这些字符串作为数据库的查询参数,那么您的数据库可能具有控制字符串相等含义的设置(对于 mysql,它是排序规则属性)
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)