Convert the first letter to the upper case and the lower case accents

0

I'm bringing from BD Mysql the user data. The names were recorded in the upper case. I'm creating a greeting for this user by taking only the first name.

list($nome,$sobrenome) = explode(" ",$pe->NomeUsuario);

The result looks like this:

  

Welcome back TÚLIO

But I want to leave it this way:

  

Welcome back Túlio

For this I tried to do the function below:

 function converter($palavra){ //
        $minusculas = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç");
        $maiusculas = array("Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
        $converter = str_replace($maiusculas, $minusculas, $palavra);
        return ucfirst($converter);
      }

 list($nome,$sobrenome) = explode(" ",converter($pe->NomeUsuario));

But the result is:

  

TuLIO

How can I convert Túlio to Tulio?

    
asked by anonymous 28.11.2018 / 17:21

2 answers

1

If it were not the accents you could use ucfirst () or ucword (), but in case it is better to use mb_convert_case ()

<?php

    $string = 'TÚLIO';

    $new_string = mb_convert_case($string, MB_CASE_TITLE, 'UTF-8');

    echo $new_string; // Túlio

?>
    
28.11.2018 / 17:32
0

Try it this way

function converter($palavra){ //
        $minusculas = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç");
        $maiusculas = array("Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
        $converter = str_replace($maiusculas, $minusculas, $palavra);
        return ucfirst(strtolower($converter));
      }

 list($nome,$sobrenome) = explode(" ",converter($pe->NomeUsuario));
    
28.11.2018 / 17:26