简体   繁体   English

某些字符导致使用PHP MySQL和XML的Web服务iPhone应用程序崩溃

[英]Certain characters causing crash in a web services iPhone app using PHP MySQL & XML

We have a live web services iPhone app where the content from the server is read from a MySQL table (Type: MyISAM ; Collation: latin1_swedish_ci ) & then sent through PHP via XML. 我们有一个实时的Web服务iPhone应用程序,其中从MySQL表(类型: MyISAM ;整理: latin1_swedish_ci )读取服务器中的内容,然后通过XML通过PHP发送。

Everything was running fine until yesterday we needed to support ◉ character. 一切运行良好,直到昨天我们需要支持◉角色。

In the XML line in our PHP we changed 在PHP的XML行中,我们进行了更改

$xml_output = "<?xml version=\\"1.0\\" encoding=\\"ISO-8859-1\\"?>\\n";

to $xml_output = "<?xml version=\\"1.0\\"?>\\n"; $xml_output = "<?xml version=\\"1.0\\"?>\\n";

And voila, along with that character, the app started supporting Emoji & International language! 瞧,那个角色,该应用程序开始支持表情符号和国际语言!

But the problem is.. now when the content contains some particular characters, the app crashes, and we are unable to detect those characters. 但是问题是..现在,当内容包含某些特定字符时,应用程序崩溃了,我们无法检测到这些字符。

As an example: When the MySQL field has this 'â¤ðŸ'˜ðŸ'UserFoo🌹â™' string, the app crashes. 例如:当MySQL字段具有此'âðð'〜ðŸ'UserFoo🌹â™'字符串时,应用程序崩溃。 The weird characters in this example are supposedly some Emoji Characters. 在这个例子中,怪异的字符可能是一些表情符号字符。

I believe this is some encoding related issue, but have no idea how to set it up alright - from insertion into table using PHP & then fetching through XML. 我相信这是一些与编码有关的问题,但不知道如何设置它-从使用PHP插入表中,然后通过XML获取。

How do I set the whole process? 如何设置整个过程? Also, it would be great if you could point to some resource for beginners that describes the whole thing with emoji support. 同样,如果您可以为初学者提供一些可以描述整个表情符号支持的资源,那就太好了。

PS: I read this question & followed the suggestion, but couldn't fix yet. PS:我读了这个问题并遵循了建议,但是还不能解决。

You should also know that most of the emoji characters are encoded using a 4 byte UTF8 codepoint which cannot be stored in MySQL unless you upgrade to version 5.5 and convert your tables to the utf8mb4 character set. 您还应该知道,大多数表情符号字符都是使用4字节UTF8码点编码的,除非升级到5.5版并将表转换为utf8mb4字符集,否则该点不能存储在MySQL中。

Reference: How to insert utf-8 mb4 character(emoji in ios5) in mysql? 参考: 如何在mysql中插入utf-8 mb4字符(ios5中的emoji)?

I am guessing that your app is crashing because the XML parser has encountered an invalid character. 我猜测您的应用程序崩溃是因为XML解析器遇到了无效字符。 The invalid character probably creeped in because of the encoding conversions that you are doing. 无效字符可能是由于您正在进行的编码转换而潜入的。 If you convert everything server side to UTF8, it will probably fix the problem, but if you accept user input then you will also need to sanitize the input to make sure that it is valid UTF8. 如果将所有服务器端都转换为UTF8,则可能会解决此问题,但是如果接受用户输入,则还需要清理输入以确保它是有效的UTF8。

I think what you should first try doing is changing your DB and table encoding to "utf8_general_ci". 我认为您首先应该尝试将数据库和表编码更改为“ utf8_general_ci”。

You should then run SET NAMES 'utf8' on your MySQL connection. 然后,您应该在MySQL连接上运行SET NAMES 'utf8' This is important so that all client communication happens in unicode. 这很重要,以便所有客户端通信都以unicode进行。

And then when you write your XML, set <?xml version="1.0" encoding="UTF-8"?> 然后,当您编写XML时,设置<?xml version="1.0" encoding="UTF-8"?>

If none of the above works, I will suggest that you also review your iPhone code and configs to ensure that special characters are supported. 如果以上方法均无效,我建议您也检查一下iPhone代码和配置,以确保支持特殊字符。

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM