Skip to content

Instantly share code, notes, and snippets.

@abelcallejo
Last active July 18, 2019 22:42
Show Gist options
  • Save abelcallejo/cb274142e9238fdf9ae5bcdf3733b687 to your computer and use it in GitHub Desktop.
Save abelcallejo/cb274142e9238fdf9ae5bcdf3733b687 to your computer and use it in GitHub Desktop.
PHP proper case function
<?php
function propername( $name, $language="es-ph" )
{
$language = str_replace("-","_",$language);
$exceptions = array(
"es_ph" => array(
"de",
"del",
"dela",
"de la",
"delos"
),
);
$ucwordsed = ucwords( strtolower( $name ) );
foreach($exceptions[$language] as $exception)
{
$ucwordsed_exception = ucwords( $exception );
$ucwordsed = str_replace( " " . $ucwordsed_exception . " ", " " . $exception . " ", $ucwordsed );
}
return $ucwordsed;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment