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 259 views
1 answer 260 views
1 answer 219 views
1 answer 240 views
2 answers 292 views
1 answer 259 views
259 views asked Jul 26, 2020 by avibootz
...