Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Criado por Bruno Pereira
- Acesse meu blog: www.projetosbrunopereira.com.br
- /*
- Para usar é simples, exemplo:
- contarVogAndCons('Essa frase tem algumas vogais e consoantes!');
- Vai printar que tem 16 vogais e 27 consoantes!
- É muito simples!
- */
- function contarVogAndCons($text) {
- $textLower = strtolower($text);
- $contText = strlen($text);
- $contVogais;
- for($bp; $bp != $contText; $bp++) {
- switch($textLower[$bp]) {
- case a: $contVogais++; break;
- case e: $contVogais++; break;
- case i: $contVogais++; break;
- case o: $contVogais++; break;
- case u: $contVogais++; break;
- }
- }
- if($contVogais == 0)
- echo "Não tem vogal!";
- else
- $cons = $contText-$contVogais;
- echo "A frase <b>$text</b> tem <b>$contVogais</b> vogais!</br>A frase <b>$text</b> tem <b>$cons</b> consoantes!";
- }
- contarVogAndCons("Essa frase tem algumas vogais e consoantes!");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement