-
-
Save parzibyte/d9d7ff89f761e1ebe5d015b3b0cea5aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!isset($_POST["cadena"])) { | |
exit("No hay cadena"); | |
} | |
$cadena = $_POST["cadena"]; | |
$transformada = ""; | |
$vocales = 0; | |
for ($i = 0; $i < strlen($cadena); $i++) { | |
$letra = $cadena[$i]; | |
# Convertir a minúscula para comprobación más simple | |
$letraMinuscula = strtolower($letra); | |
# Saber si es vocal. Para ello comprobamos si la letra está en el arreglo de vocales | |
if (in_array($letraMinuscula, ["a", "e", "i", "o", "u"])) { | |
# En caso de que sí, entonces en lugar de agregar el caracter, agregamos un ¿ | |
$transformada .= "¿"; | |
# Y aumentamos el contador | |
$vocales++; | |
} else { | |
# En caso de que no, agregamos el carácter normalmente | |
$transformada .= $cadena[$i]; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment