Search code examples
phppreg-replaceereg-replace

quick ereg_replace to preg_replace


I am learning PHP functions and have this problem:

I need to change the function *ereg_replace*

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

to *preg_replace*

how to do it ?

Thank you


Solution

  • Well, this is not a regular expression that you are using. What you want here is str_replace.

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

    Rather read up about what regular expressions are and how they work.