Skip to content

Instantly share code, notes, and snippets.

@tounsils
Created November 8, 2018 13:32
Show Gist options
  • Save tounsils/6269a9429f15767b01820ab4de0af7bb to your computer and use it in GitHub Desktop.
Save tounsils/6269a9429f15767b01820ab4de0af7bb to your computer and use it in GitHub Desktop.
Displays vowels and number of vowels in a string using regex
$str = "Created by PhpStorm.
* User: Tounsi
* Date: 30/10/2018
* Time: 11:59
*
* List of vowels in string";
$nbVowels = 0;
for($i=0;$i<strlen($str);$i++)
{
$letter = $str[$i];
if(preg_match('/[aeuioAEUIO]/',$letter)){
$nbVowels++;
echo $letter;
}
}
echo "<br>number of vowels = $nbVowels :)";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment