Well, I was going to try a recursive call to ucfirst_some()
, but your code appears to work just fine without the first line. ie:
<?php
$major = 'accounting technology/technician and bookkeeping';
$major = preg_replace_callback("/[a-zA-Z]+/",'ucfirst_some',$major);
echo ucfirst($major);
function ucfirst_some($match) {
$exclude = array('and','of','the');
if ( in_array(strtolower($match[0]),$exclude) ) return $match[0];
return ucfirst($match[0]);
}
Prints the desired Accounting Technology/Technician and Bookkeeping
.
Your regular expression matches strings of letters already, you don't seem to need to worry about the slashes at all. Just be aware that a number or symbol [like a hyphen] in the middle of a word will cause the capitalization as well.
Also, disregard the people harping on you about your $exclude
array not being complete enough, you can always add in more words as you come across them. Or just Google for a list.