you're using explicit hard coded values in your example, so the easiest is to use str_replace
instead of str_ireplace
, and just do a pass for both lowercase and uppercase string replacements. You can simply build the uppercase and sentence case arrays off the lower case array, and then you don't even need to do any work:
$find_lc = array('moo', 'cow', 'something');
$find_uc = array_map('str_to_upper', $array);
$find_sc = array_map('ucfirst', $array);
$searches = array($find_lc, $find_uc, $find_sc);
$replace_lc = array(...);
$replace_uc = array(...);
$replace_sc = array(...);
$replacements = array($replace_lc, $replace_uc, $replace_sc);
$converted = $input;
for($i=0; $i<count($searches); $i++) {
$converted = str_replace($searches[$i], $replacements[$i], $converted);
}
And now it'll simply be correctly case-replaced. A little verbose perhaps, and you need hardcoded lists, but your question seemed pretty specific instead of asking about "any possible word" (in which case you'll need to use something like preg_replace_callback)