Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // This function prints unique vowels (A, E, I, O, U)
- // from a given string in the order they appear.
- // A 'Y' is considered a consonant if it begins a string and this string is greater than 1 character.
- // Otherwise, a 'Y' is considered a vowel.
- function findVowels ($string) {
- //Handle 'Y' as a consonant
- if(strlen($string) > 1) {
- $string = preg_replace("/^y?/i", "", $string);
- }
- //Leave only vowels in the string
- $pattern = "/[^aeiouy]?/i";
- $string = preg_replace($pattern, '', $string);
- //Remove dublicate characters
- $string = implode(array_unique(str_split($string)));
- return $string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement