I'm intrigued...
What is the str_ireplace function?
I would have just used
str_replace('<br'>, '<br>');
str_replace(' ', '&nbsp;');
str_ireplace is the same as str_replace, except it ignores case (ie "<br>" and "<BR>" would both be replaced). Most string functions have a counterpart that ignores case, that's what the "i" stands for.
I don't know how experienced you are with PHP, so this explanation may be a little confusing: str_replace can accept arrays for arguments as well as strings. If you give it an array, it will work through each element and replace it like normal. Check the function reference page:
http://us2.php.net/manual/en/function.str-ireplace.php . Your code and garret's will do the same thing. I'll rewrite his code so it's easier to visualize:
Code:
function ReplaceBR_NBSP($input_str)
{
$search[0] = '<br>';
$search[1] = ' ';
$replace[0] = '<br>';
$replace[1] = '&nbsp;';
return str_ireplace($search, $replace, $input_str);
}
PS - I reread your post, do you want to convert everything to html entities EXCEPT "<br>" and " ", or ONLY those two strings, because that function will replace ONLY those two. If you want it the other way around, do $input_str = htmlentities($input_str), then switch $search and $replace. That way, it will convert everything, then revert line breaks and spaces to the way they were before.