Unfortunately, there is a problem with this. One-syllable names ending in 's' take an apostrophe s. A simple way around this is a regex.
So, LordShryku's code could be:
if(substr($name, -1) == "s") {
if(preg_match("/^[bcdfghjklmnpqrstvwxyz]*[aeiouy]+[bcdfghjklmnpqrstvwxyz]+[aeiouy]+/i", $name)){
$newName = $name."'";
} else {
$newName = $name."'s";
}
}
else {
$newName = $name."'s";
}
What this new code does is it tries to check if a word is two syllables or longer. However, this may not always work, but is definitely better than nothing.