Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. <?php
  2.  
  3. // This function prints unique vowels (A, E, I, O, U)
  4. // from a given string in the order they appear.
  5. // A 'Y' is considered a consonant if it begins a string and this string is greater than 1 character.
  6. // Otherwise, a 'Y' is considered a vowel.
  7.  
  8. function findVowels ($string) {
  9.  
  10. //Handle 'Y' as a consonant
  11. if(strlen($string) > 1) {
  12. $string = preg_replace("/^y?/i", "", $string);
  13. }
  14.  
  15. //Leave only vowels in the string
  16. $pattern = "/[^aeiouy]?/i";
  17. $string = preg_replace($pattern, '', $string);
  18.  
  19. //Remove dublicate characters
  20. $string = implode(array_unique(str_split($string)));
  21.  
  22. return $string;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement