0

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).

msabate
  • 335
  • 1
  • 2
  • 16
  • `à` and `a` is not the same. add `à` to the `$modifications` array – Saeed M. Apr 13 '18 at 10:53
  • Why don't you replace directly `à` with `À` etc... ? (if encoding is consistent in your appli) – Déjà vu Apr 13 '18 at 10:54
  • Why are you comparing entities to a string? Surely, that's the reason it doesn't work. – Script47 Apr 13 '18 at 10:54
  • I know, but if I do it I get à. I have explained below the code – msabate Apr 13 '18 at 10:55
  • 1
    Possible duplicate of [Replacing accented characters php](https://stackoverflow.com/questions/3371697/replacing-accented-characters-php) – Script47 Apr 13 '18 at 10:55
  • @Script47 I have the same explanation why is not working, but how can I fix it? – msabate Apr 13 '18 at 10:55
  • *How can I get JOHN SERAN MOLLO (without accents)* vs *how can I could get JOHN SERÀN MOLLÒ (accents in upper case).* - Which one do you want or do you want both? Please clarify. – Script47 Apr 13 '18 at 10:56
  • 1
    Have you tried `mb_strtoupper` instead? – iainn Apr 13 '18 at 10:57
  • @Script47 I prefer to get the second one, but it doesn't matter if I can get the first one because the second one is not possible – msabate Apr 13 '18 at 10:58

2 Answers2

1

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

iainn
  • 16,826
  • 9
  • 33
  • 40
0

Use strtoupper() function or mb_strtoupper() function. Woohaa just try this... Have a good Day... 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"

?>
sreechith srk
  • 146
  • 12