如何使用php从数据库中解析带有特殊字符的字符串?
我有一个 MySQL 数据库,里面有道路名称。当我从数据库中查询时,有一个条目给我带来了问题:Osmeña Avenue。我使用 Java 将数据存储到数据库,然后使用 phpMyadmin 查看数据,然后我看到 4f736d65c3b161204176656e7565 而不是 Osmeña Avenue。当我查询名称时,我将它们放入一个 XML 文件中,并将其用于我的应用程序。当我查询 Osmeña Avenue 时,我的程序冻结了。我发现在 XML 文件中,ñ 被替换为 �,这导致了冻结。首先,为什么我在 phpMyAdmin 视图中看到 Osmeña Avenue 的一堆数字?我该如何使用 PHP 从数据库中获取带有特殊字符的正确字符串?提前致谢!
编辑: XML 文件用于使用 OpenLayers.Format.KML; 绘制路线。
I had a MySQL database with names of roads in it. There is this one entry that gives me problems when I query it from the database: Osmeña Avenue. I stored the data to the DB using Java, and then I viewed the data using phpMyadmin then I saw 4f736d65c3b161204176656e7565 instead of Osmeña Avenue. When I query for the names, I placed them inside an XML file, which I use for my application. When I query for Osmeña Avenue, my program freezes. I found out that in the XML file, the ñ is replaced by a �, which causes the freeze. First, why do I saw a bunch of numbers in the phpMyAdmin view for Osmeña Avenue? And what can I do to get the right string with the special characters from the database using PHP? Thanks in advance!
EDIT:
the XML file is used to draw routes using OpenLayers.Format.KML;.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
4f736d65c3b161204176656e7565
是表示Osme\xc3\xb1a Avenue
的字节序列 (4f
,73
,..) ,这是Osmeña Avenue
的 UTF-8 表示形式。只需正确解码您的数据即可。在您的应用程序中,继续仅使用 Unicode 字符串,并在系统边缘对字符串数据进行编码/解码。
4f736d65c3b161204176656e7565
is a sequence of bytes (4f
,73
,..) that representOsme\xc3\xb1a Avenue
, which is the UTF-8 representation ofOsmeña Avenue
.Just decode your data properly. Inside your app, keep working only with Unicode strings, and encode/decode string data at system edges.
不要使用
utf8_bin
,而是使用utf8_general
。或者,最好只使用
latin1_swedish_ci
或latin1_swedish_cs
。Don't use
utf8_bin
, useutf8_general
instead.Or, it would be even better to just use
latin1_swedish_ci
orlatin1_swedish_cs
.