0

I want to write \r\n in file, not for making new line but literal text. The line I want to write in the file is

To make a new line write \n in the end of the line

My php code is like this

$handle = fopen("a.txt","w+");
$text = "To make a new line write \r\n in the end of the line\r\n";
fwrite($handle, $text);
fclose($handle);

But it is writing

To make a new line write
in the end of the line

That \r\n is parsed as newline. How can I write that text in the file?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Razin Abid
  • 349
  • 3
  • 15

1 Answers1

3

You can do it this way:

$text = 'To make a new line write \r\n in the end of the line'."\r\n";

As this chars are not parsed if they are between single quotes.

Or escape the \ with \\ if you must use double quotes.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
jeprubio
  • 17,312
  • 5
  • 45
  • 56