gpt4 book ai didi

php - 可能的字符编码问题?

转载 作者:行者123 更新时间:2023-11-29 22:15:19 26 4
gpt4 key购买 nike

我正在制作一个简单的博客 Android 应用程序,用户可以在其中添加/查看博客。现在对于博客添加,有一个简单的 TextView ,用户可以在其中添加博客内容(博客文本)。然后,该博客内容通过 HttpPost 传输到 php 脚本,然后将其存储在 MySQL 数据库中。

现在我的问题是用户可以将博客内容的文本复制粘贴到 TextView 中。这种复制粘贴的来源可以是从互联网页面到教科书的任何地方。文本也可以是任何字体、颜色等。这可能会导致字符编码问题,因为每当我尝试将文本复制粘贴到博客正文中时,博客提交都会失败...否则它工作正常。我的 MySQL 数据库排序规则是 UTF-8。

我的问题是:如何将具有任何编码的任何可能来源的文本转换为 utf-8?

最佳答案

看看https://github.com/neitanod/forceutf8

来自他们的文档:

You don't need to know what the encoding of your strings is. It can be Latin1 (iso 8859-1), Windows-1252 or UTF8, or the string can have a mix of them. \ForceUTF8\Encoding::toUTF8() will convert everything to UTF8.

Sometimes you have to deal with services that are unreliable in terms of encoding, possibly mixing UTF8 and Latin1 in the same string

关于php - 可能的字符编码问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31253813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com