I don't think there's an easy way (someone please correct me if I'm wrong), but you could try
function matchCase($matches)
{
$replacement = 'howdie';
if (ctype_upper($matches[0])){
return strtoupper($replacement);
} else if (ctype_upper(substr($matches[0],0,1))){
return ucwords($replacement);
} else {
return strtolower($replacement);
}
}
$input = "Hello hello HELLO HeLLo hEllO";
$output = preg_replace_callback("/hello/i", "matchCase", $input);
echo $output;
As you can see, it only deals with all uppercase, all lowercase or first letter capitalized, ignoring single uppercase letters later within the word, so: feel free to modify & improve.