$cleanArr[$key] = preg_replace("/\r/", "", $val);
$cleanArr[$key] = preg_replace("/\n/", "", $val);
This isn't stripping "\r" from $cleanArr[$key], only "\n".
$val = str_replace("\r", "", $val);
$cleanArr[$key] = str_replace("\n", "", $val);
(I also replaced preg_replace with str_replace in the interests of efficiency).
Here's another way of writing the function. Not necessarily better, but different.
function removeNewlines($passedExceptions=array())
{
$cleanArr = array();
$keys = array_diff(array_keys($this->passedArr), $passedExceptions);
foreach($keys as $key)
{
$val = str_replace("\r", "", $this->passedArr[$key]);
$cleanArr[$key] = str_replace("\n", "", $val);
}
return $cleanArr;
}
I notice that the function discards any elements with keys that appear in $passedExceptions (and doesn't just leave them with their newlines intact). Is this intended?