settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Vowels Count - PHP Function Task

+3 votes

Write a function that receives a single string and prints the count of the vowels. Use appropriate name for the function.

Examples:

vowels count php function task

asked in PHP category by user icabe

1 Answer

+2 votes

Here is my answer:

<?php

$word = readline();

echo countVowels($word);

function countVowels($input) {
    $count = 0;
    for ($i = 0; $i < strlen($input); $i++) {
        $current = strtolower($input[$i]);
        if ($current == "a" || $current == "u" || $current == "i" || $current == "e" || $current == "o") {
            $count++;
        }
    }
    return $count;
}
answered by user eiorgert
...