How to count the number of vowels in a string with PHP

1 Answer

0 votes
function count_vowels($s) {
    preg_match_all('/[aeiou]/i', $s, $match_arr);

    return count($match_arr[0]);
}

echo count_vowels('PHP is a general-purpose programming language');



/*
run:

15
 
*/

 



answered Mar 1, 2019 by avibootz

Related questions

1 answer 151 views
1 answer 171 views
1 answer 131 views
1 answer 139 views
2 answers 180 views
1 answer 165 views
165 views asked Jul 26, 2020 by avibootz
...