Returns number of vowels in the provided string.

Use a regular expression to count the number of vowels (a, e, i, o and ua) in a string.

代码实现

function countVowels($string)
{
  preg_match_all('/[aeiou]/i', $string, $matches);

  return count($matches[0]);
}

使用样例

countVowels('sampleInput'); // 4