I have the following code that converts a lowercase letter to uppercase
Code:
<?php
echo "<h2>Letra minuscula a mayuscula</h2>";
$letra = "m";
echo "La letra minuscula es: ".$letra."<br>";
echo "Pasando la letra minuscula a la funcion...<br><br>";
function minusToMayus($letra)
{
$ascii = ord($letra);
echo "La letra ".$letra." tiene como ascii: ".$ascii."<br>";
$letra = chr($ascii - 32);
echo "Le restamos 32 para obtener el codigo ascii de su mayuscula<br><br>";
return $letra;
}
$letra = minusToMayus($letra);
echo "La letra minúscula se a convertido mayúscula: ".$letra;
?>
How would it be for instead of converting a letter it was a word? Would I have to convert a string to an array?
You already have it done for a letter. Doing it for a sentence would be very simple: you just have to loop through the string and transform each letter individually.
For example, here it is with a loop
for
:Using the function that I have left you in this answer and making some changes, it would look like this (explanation in the comments):
Ver Demo Online