Just $test = str_replace(array("\n", "\r"), array('\n', '\r'), $data['test']);