Count Vowels Function
PHP
Easy
7 views
Problem Description
Write a function that counts vowels in a string (a,e,i,o,u).
Input Format
One line string s.
Output Format
One integer count.
Official Solution
<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
function countVowels($t){
$t=strtolower($t);
$c=0;
for($i=0,$n=strlen($t);$i<$n;$i++){
$ch=$t[$i];
if($ch==='a'||$ch==='e'||$ch==='i'||$ch==='o'||$ch==='u') $c++;
}
return $c;
}
echo countVowels($inputText);
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!