Jump to content

Writing file without \r\n translation


frog_jr

Recommended Posts

I am in a brain freeze!

I am trying to output strings (obtained from an array) to a file. The string contains \r and \n characters that are not to be interpreted as newlines but written as is to the file.

There are also multiple \'s that can be present...

 

Everything I've tried thus far (addslashes, quotemeta, ...) has had no effect.

For example:

         $test = array("str\rv?\n","as\\\\n\df");
         file_put_contents("Myfile",$test[0]);  // first value to file
         file_put_contents("Myfile","\n");      // a newline
         file_put_contents("Myfile",$test[1]);  // put another value

How do I get this data into the file?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/200007-writing-file-without-rn-translation/
Share on other sites

USE "addslashes" function

 

$test = array('str\rv?\n','as\\\\n\df');

        file_put_contents("Myfile", addslashes($test[0]));  // first value to file

        file_put_contents("Myfile","\n");      // a newline

        file_put_contents("Myfile",addslashes($test[1]));  // put another value

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.