Вам необходимо оценить каждое слово отдельно:
if( strtoupper($word) != $word ){
$word = ucwords($word);
}
Это означает разбиение любых строк на пробелы и оценку каждой части отдельно.
ОБНОВЛЕНИЕ:
Вот рабочий пример:
// put these into an array to demo the logic
$s1="ABcd Efg";
$s2="abcd EFG";
$words_array = array($s1,$s2);
foreach( $words_array as $words ){
echo "Old words: $words\n";
// inline replace of words
$split_words = explode(" ",$words);
for( $i=0; $i<count($split_words); $i++ ){
$word = $split_words[$i];
if( strtoupper($word) != $word ){
$split_words[$i] = ucwords(strtolower($word));
}
}
echo "New words: ".implode(" ",$split_words)."\n";
}