Skip to content

Instantly share code, notes, and snippets.

@joeybaker
Created May 2, 2012 20:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeybaker/2579985 to your computer and use it in GitHub Desktop.
Save joeybaker/2579985 to your computer and use it in GitHub Desktop.
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