The strtoupper()
function of PHP is not transforming the letters with a capital accent, see example:
echo strtoupper("virá"); // retorna VIRá
Do you have a native function that solves this problem?
The strtoupper()
function of PHP is not transforming the letters with a capital accent, see example:
echo strtoupper("virá"); // retorna VIRá
Do you have a native function that solves this problem?
You need to use your counterpart, mb_strtoupper () that will handle unicode: / p>
$encoding = mb_internal_encoding(); // ou UTF-8, ISO-8859-1...
echo mb_strtoupper("virá", $encoding); // retorna VIRÁ
or
$encoding = 'UTF-8'; // ou ISO-8859-1...
mb_convert_case('virá', MB_CASE_UPPER, $encoding);
This is because mb_ * functions will operate on strings based on their Unicode properties. Accented characters are not regular "formations", but multibytes. That is why if you use strlen ("will") the result will be 5 characters, instead of 4 (as you expected).
Since we can not guess in which encoding in which to save the files and in which encoding is used in the output, we can not enter the correct one here. You should find out. The best advice is to save the source files in UTF-8 (every editor has this option) and output the output force in UTF-8, using tag <meta charset="SEU-ENCODING">
mb_strtoupper('virá', 'UTF-8');
Or
mb_internal_encoding('UTF-8');
mb_strtoupper('virá');
In addition to having to deal with accentuation of the strtoupper
function, I also had to cast cast with the data coming from the database,
mb_strtoupper(utf8_encode($variavel_do_banco['nome_coluna_banco']));
If you use ISO-8859-1
header ('Content-type: text/html; charset=ISO-8859-1');
echo mb_strtoupper("maçãs são boas", 'ISO-8859-1');