Search code examples
phpescapingslash

escaping slashes using php


I am trying to remove the escape sequences present in between my output. I am coding using php and I have output from the function and it contains escape sequences like \r and \n. How do I escape these stuff from output so that I get a proper output. The issue is that I am trying to add this output to a csv file, so it will take \n as next line.


Solution

  • Use str_replace function:

    $your_string =  "here is your string"
    
    $your_string = str_replace("\n", "", $your_string);
    $your_string = str_replace("\r", "", $your_string);