On second thought, since neither ucfirst
nor ucwords
ever translates an uppercase character to its lowercase counterpart; ucwords
should be fine for this case. I've changed the function below, so that it will make it more normative though, which would be necessary depending on how you interpret the question.
You'll need to define your own function to do this; PHP has no function with this behavior in its standard library (see note above).
// Let's create a function, so we can reuse the logic
function sentence_case($str){
// Let's split our string into an array of words
$words = explode(' ', $str);
foreach($words as &$word){
// Let's check if the word is uppercase; if so, ignore it
if($word == strtoupper($word)){
continue;
}
// Otherwise, let's make the first character uppercase
$word = ucfirst(strtolower($word));
}
// Join the individual words back into a string
return implode(' ', $words);
}
echo sentence_case('product manufacturer for CAMERON TRAILERS');
// "Product Manufacturer For CAMERON TRAILERS"