Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
strtotitle – php to title case a string
# converts a string to title case
# input: string
# output: string in title case
function strtotitle($title) {
$blacklist = array( 'of','a','the','and','an','or','nor','but','is','then','else', 'at','from','by','on','off','for','in','out','over','to','into','with' );
$words = explode(' ', $title);
foreach ($words as $key => $word) {
if ($key == 0 || !in_array($word, $blacklist))
$words[$key] = ucfirst($word);
}
$newtitle = implode(' ', $words);
return $newtitle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment