It seems to be simple, but I have problem.
ereg_replace("\n","\\n",$row)
into preg_replace.
Anyone could give me a hand?
The only thing you need to change (except function name) is to add delimiters to the pattern (slashes in this case):
preg_replace("/\n/", "\\n", $row);
However, in this particular case you do not need to use regexes (which are slow enough), simple str_replace would be fine:
str_replace("\n", "\\n", $row);