Q:

Write a PHP program to count number of vowels in a given string

0

Write a PHP program to count number of vowels in a given string.

Note: Use a regular expression to count the number of vowels (A, E, I, O, U) in a string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
//Licence: https://bit.ly/2CFA5XY

function count_Vowels($string)
{
    preg_match_all('/[aeiou]/i', $string, $matches);
    return count($matches[0]);
}
print_r(count_Vowels('sampleInput'));


?>

Sample Output:

4

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now