dongshie8450 2017-09-30 17:22
浏览 67
已采纳

PHP - Mysql中的拉丁字符

I'm having a rather strange problem: I am working with a database (which I did not design), this database is multi-lingual, that is, there are titles in English, Spanish, Russian, Vietnamese, etc.

From what I have seen titles with characters of type "ñ", "á", "é", "ë", have been stored in the database in this way: "&ntilde_", so I know in html for show these characters how to write them is "ñ" in my PHP code at the time of calling these characters (without using any type of conversion) the following happens to me:

Title in database: Se&ntilde_ora // Señora
Title obtained by PHP: Señ_ora // Señora

I tried using utf_decode and html_entities_decode but this did not work. I wanted to do this, use a str_replace to remove the "_" from the title "Señ_ora" but I got: "Se&ntildeora"

  • 写回答

2条回答 默认 最新

  • doupang3062 2017-09-30 17:49
    关注

    characters of type "ñ", "á", "é", "ë", have been stored in the database in this way: "&ntilde_"

    This is bizarre.

    First of all, make sure your database actually contains these _ characters, and make sure you're not seeing some sort of substitution character being rendered. Whatever program you're using to show the data might have some character set option set incorrectly.

    You might say SELECT field, HEX(field) FROM table WHERE field LIKE '%' ORDER BY CHAR_LENGTH(field) LIMIT 10 to find a few relatively short examples. Then pore over the hex output looking for 3B (hex for ;) and 5F (hex for _).

    For example, SELECT HEX('Señora'), HEX('Se&ntilde_ora') on my UTF8 setup gives these two strings

    5365266E74696C64653B6F7261
                      xx
    5365266E74696C64655F6F7261
    

    See the difference?

    If the _ characters are definitely in your data, you have some cyber-speklunking to do. Do you have access to the person who set this up, so you can ask about it? If so, do. It will save you some reverse-engineering time.

    If you have to fix this without help, you can try using php like this

     $my_data = str_replace('_',';', $my_data);
    

    That should get the entitized characters to be formatted correctly. But, it will also change standalone _ characters to ;. To fix this right, you'll need a list of all the entitized characters in your data, and you'll need to change them individually.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch