<?
// Enable the title to be correctly capitalized
// Except for a, an. the, bu, as if, and, or, nor, of, by, the first letter of all other words is capitalized.
Function title_upcase ($ str ){
// Uppercase
$ Str = ucwords ($ str );
// Returns an array containing all the words in the string and indexed by the position of the word in the string.
$ Wordlist = str_word_count ($ str, 2 );
// Exclude the first and last elements in the array, because it does not need to be changed to lowercase.
$ Wordlist = array_slice ($ wordlist, 1,-1, true );
// If the following words are contained, all lowercase letters are used.
Foreach ($ wordlist as $ position => $ word ){
Switch ($ word ){
Case 'A ':
Case 'A ':
Case ''the ':
Case 'but ':
Case 'as ':
Case 'if ':
Case 'and ':
Case 'or ':
Case 'nor ':
Case 'of ':
Case 'by ':
$ Lower = strtolower ($ word );
$ Str {$ position }=$ lower {0 };
}
}
Return $ str;
}
?>
Function Description and example
<?
$ Sample = "a study of interesteller galaxies as presented by scientist ";
$ Upcased = title_upcase ($ sample );
Echo $ sample; // a study of interesteller galaxies as presented by scientist
Echo $ upcased; // A Study of Interesteller Galaxies as Presented by Scientist
?>