Created
May 26, 2015 15:22
-
-
Save franklinjavier/2b19a669151cddf6467c to your computer and use it in GitHub Desktop.
Converte uma palavra no plural para o singular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Converte uma palavra no plural para o singular | |
| * @param string $str Uma palavra | |
| * @return string Palavra no singular | |
| * | |
| * https://github.com/Moraga/PluralToSingular | |
| * | |
| */ | |
| function pluraltosingular($str) { | |
| if (substr($str, -1) != 's') | |
| return $str; | |
| // albuns batons marrons | |
| if (substr($str, -2, 1) == 'n') | |
| return substr($str, 0, -2) . 'm'; | |
| // flores gizes vezes tenis | |
| else if (strpos('aeou', substr($str, 0, 1)) === false && substr($str, -2, 1) == 'e' && strpos('nrsz', substr($str, -3, 1)) !== false) | |
| return substr($str, 0, -2); | |
| // aneis anzois jornais | |
| else if (substr($str, -2) == 'is' && strpos('aeiou', substr($str, -3, 1)) !== false) | |
| return substr($str, 0, -2) . 'l'; | |
| // frances portugues | |
| else if (substr($str, -2) == 'es' && strpos('clu', substr($str, -3, 1)) !== false) | |
| return $str; | |
| // caes paes | |
| else if (substr($str, -3) == 'aes') | |
| return substr($str, 0, -2) . 'o'; | |
| // leoes | |
| else if (substr($str, -3) == 'oes') | |
| return substr($str, 0, -3) . 'ao'; | |
| // exceto onibus lapis tenis arvores | |
| else if (strpos('ius', substr($str, -2, 1)) === false && substr($str, -3, 1) != 'n') | |
| return substr($str, 0, -1); | |
| return $str; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Moraga é o pai dessa função https://github.com/Moraga/PluralToSingular