I have the following statement: I have to count the total characters of a string, count the total number of vowels, and the number of times each vowel appears. I lose myself a bit and I've done it without a loop while. I can not use arrays either. The mistake I get when I want to count vowels separately is:
Warning: substr() expects parameter 2 to be integer, string given in /opt/lampp/htdocs/pruebaexamen/ejercicio1.php on line 5
Warning: substr() expects parameter 2 to be integer, string given in /opt/lampp/htdocs/pruebaexamen/ejercicio1.php on line 6
Warning: substr() expects parameter 2 to be integer, string given in /opt/lampp/htdocs/pruebaexamen/ejercicio1.php on line 7
Warning: substr() expects parameter 2 to be integer, string given in /opt/lampp/htdocs/pruebaexamen/ejercicio1.php on line 8
Warning: substr() expects parameter 2 to be integer, string given in /opt/lampp/htdocs/pruebaexamen/ejercicio1.php on line 9
The PHP code:
<?php
$texto = $_POST['texto'];
$caracteres = strlen($texto);
$vocales = substr_count($texto, 'a')+substr_count($texto, 'e')+substr_count($texto, 'i')+substr_count($texto, 'o')+substr_count($texto, 'u')+substr_count($texto, 'A')+substr_count($texto, 'E')+substr_count($texto, 'I')+substr_count($texto, 'O')+substr_count($texto, 'U');
$a = substr_count($texto, 'a') + substr($texto, 'A');
$e = substr_count($texto, 'e') + substr($texto, 'E');
$i = substr_count($texto, 'i') + substr($texto, 'I');
$o = substr_count($texto, 'o') + substr($texto, 'O');
$u = substr_count($texto, 'u') + substr($texto, 'U');
echo "El número total de caracteres es $caracteres <br/>";
echo "El total de vocales es $vocales <br/>";
echo "El numero de letras a (mayúsculas incluidas) es $a <br/>";
echo "El numero de letras e (mayúsculas incluidas) es $e <br/>";
echo "El numero de letras i (mayúsculas incluidas) es $i <br/>";
echo "El numero de letras o (mayúsculas incluidas) es $o <br/>";
echo "El numero de letras u (mayúsculas incluidas) es $u <br/>";
?>