简体   繁体   English

str_replace带有“ grave”重音

[英]str_replace with “grave” accent

I'm developing a web and I want to print some information from DB. 我正在开发一个Web,我想从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. 例如,我有以下信息:JohnSerànMollò,我需要将其转换为大写。 This should be the result: JOHN SERÀN MOLLÒ 结果应该是:JOHNSERÀNMOLLÒ

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ò. 在那种情况下,结果应该是JOHN SERAN MOLLO(不带重音),但我明白了:JOHNSERàNMOLLò。

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). 我如何获得JOHN SERAN MOLLO(不带重音),或者,如果可能的话,如何获得JOHNSERÀNMOLLÒ(带大写字母的重音)。

If your installation has the mbstring extension loaded (most do, in my experience), you should be able to use mb_strtoupper , eg 如果您的安装加载了mbstring扩展名(根据我的经验,大多数情况下这样做),则应该可以使用mb_strtoupper ,例如

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 如果该功能不可用,则可以在此处使用polyfill: https : //github.com/symfony/polyfill-mbstring

Use strtoupper() function or mb_strtoupper() function. 使用strtoupper()函数或mb_strtoupper()函数。 Woohaa just try this... Have a good Day... Seeya... 哇,快试试看...祝你有美好的一天... Seeya ...

<?php

setlocale(LC_CTYPE, 'de_DE.UTF8');

echo strtoupper('Umlaute äöü in uppercase'); // outputs "UMLAUTE äöü IN UPPERCASE"
echo mb_strtoupper('Umlaute äöü in uppercase', 'UTF-8'); // outputs "UMLAUTE ÄÖÜ IN UPPERCASE"

?>

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

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