The first part says if the argument string is mixed case, leave it alone,
otherwise apply "proper" capitalization to it. This is easy to translate
into php:
if (strtolower($str) == $str || strtoupper($str) == $str)
{
$str = ucwords( strtolower( $str ) );
}
The rest I'm going to have to pass on...