A handy function to create a string for use as a title.
/**
* Converts a string to title case, capitalising all major words
*
* @param string $string The string to process
* @return string The resulting string
*/
function title_case($string){
$exceptions = array('the', 'and', 'nor', 'but', 'then', 'else', 'when', 'from', 'off', 'for', 'out', 'over', 'into', 'with');
$words = explode(' ', strtolower($string));
foreach ($words as &$word){
if (!in_array($word, $exceptions) && strlen($word) > 2){
$word = ucfirst($word);
}
}
return implode(' ', $words);
}
Feel free to use this wherever you like, no need to give credit.