douqi3064 2018-04-13 10:51
浏览 24
已采纳

带有“严重”重音的str_replace

I'm developing a web and I want to print some information from DB. I have found the problem that information with "grave" accent it is not possible to convert to upper case.

For example, I have the following information: John Seràn Mollò and I need to convert it to upper case. This should be the result: JOHN SERÀN MOLLÒ

I'm trying the following code:

            $filtre = array("&agrave", "&egrave", "&ograve");
            $modificacions = array("a", "e", "o");
            $phrase = str_replace($filtre, $modificacions, $vols[$i]['crew']);
            var_dump($phrase);
            echo strtoupper($phrase); ?>

In that case, the result should be JOHN SERAN MOLLO (without the accents), but I get this: JOHN SERàN MOLLò.

What I'm doing bad? How can I get JOHN SERAN MOLLO (without accents) or, if it's possible, how can I could get JOHN SERÀN MOLLÒ (accents in upper case).

  • 写回答

2条回答 默认 最新

  • dpmp9359 2018-04-13 11:05
    关注

    If your installation has the mbstring extension loaded (most do, in my experience), you should be able to use mb_strtoupper, e.g.

    echo mb_strtoupper($phrase);
    

    This will use the default internal encoding by default, so should be all you need, but you may also need to provide a second argument to specify the string encoding.

    If the function isn't available, there's a polyfill available here: https://github.com/symfony/polyfill-mbstring

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

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装