Guest User

Untitled

a guest
Oct 23rd, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. *
  5. * Pig Latin is a game of alterations played on the English language game.
  6. * To create the Pig Latin form of an English word the initial consonant sound is transposed to the end of the word
  7. * and an ay is affixed (Ex.: "banana" would yield anana-bay).
  8. * Read Wikipedia for more information on rules.
  9. *
  10. */
  11. function pigLatin(string $str){
  12.  
  13. if(!ctype_alpha($str)){
  14. throw new InvalidArgumentException('в строке могут быть только буквы');
  15. }
  16.  
  17. $str = strtolower($str);
  18.  
  19. define('VOWELS', array('a','e', 'i', 'o', 'u', 'y'));
  20.  
  21. $i = 0;
  22. while($i<=strlen($str)-1){
  23. if(!in_array($str[$i],VOWELS)){
  24. $str .= $str[$i];
  25. $str = substr($str, 1);
  26. }else{
  27. break;
  28. }
  29. }
  30.  
  31. return $str . "ay";
  32. }
  33.  
  34. var_dump(pigLatin('three'));
Add Comment
Please, Sign In to add comment