5

I have a script that throws me errors because I run PHP 5.3.1
What Do I have to use in the example?

$row[$j] = ereg_replace("\n", "\\n", $row[$j]);

Deprecated: Function ereg_replace() is deprecated in..

FFish
  • 11,014
  • 33
  • 93
  • 135
  • 1
    I was searching for script to backup my mysql database and found this [http://davidwalsh.name/backup-mysql-database-php](http://davidwalsh.name/backup-mysql-database-php) article and then I found this post which is exactly what I was looking for – Ing. Michal Hudak Dec 05 '13 at 09:36

2 Answers2

20

Use preg_replace instead, just add delimiters.

$row[$j] = preg_replace("#\n#", "\\n", $row[$j]);
Jim
  • 18,348
  • 5
  • 47
  • 64
  • 4
    +1 for mentioning the delimiters, and that they don't have to be forward slashes. – Skilldrick Nov 19 '10 at 14:57
  • Did you miss an 's' at the end of the pattern? Doesn't ereg_replace implicitly behave like an "/s" at the end. – Basil Musa Sep 29 '14 at 20:28
  • @BasilMusa I do not know, everything I have converted I did not require an `s` at the end. From what I remember of `ereg_replace` was that it just omitted the delimiters, but it is possible it also did an `s` as well. Really just depends on the regex I guess. – Jim Sep 29 '14 at 22:34
2

Use the preg_replace function instead.

Marc B
  • 348,685
  • 41
  • 398
  • 480