In PHP str_replace (), what does double backslash mean?

I want to delete everything \r \n \r\n, which is pretty easy, so I wrote:

str_replace(array("\r","\n"),"",$text);

but I saw this line:

str_replace(array("\r","\n","\\r","\\n"),"",$text);

and I was wondering what a double backslash is \\rand \\n.

+4
source share
2 answers

\ is an escape character, it is used to exit the next character.

The "\n"backslash is reset n, and the result will be a newline .

"\\n" , n , , \n ().

. PHP > .

str_replace() ("\n" "\r"), \n \r ("\\n" "\\r" ). \n \r, , "\\n" "\\r" .

+6

, $text.

, , .

+2

All Articles