Last active
July 18, 2019 22:42
-
-
Save abelcallejo/cb274142e9238fdf9ae5bcdf3733b687 to your computer and use it in GitHub Desktop.
PHP proper case function
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 | |
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