Search code examples
phpjquerynewlinefwrite

Write XHR data with line break


I get some data from a variable, and send it via XHR to PHP file which write it in to a file. How can I make a line break in the file after every write to it?

var e='Hello world!'
$.getJSON('http://example.com/write.php?callback=&data='+e);

write.php:

$data = $_GET['data'];
if(!$op=fopen('my file name','ab')){
  $res='b';
  exit;
}
if(fwrite($op,$data)===FALSE){
  $res='b';
  exit;
}
fclose($op);

Solution

  • Try writing or appending a PHP_EOL to the file after you have written your data.

    fwrite($op, PHP_EOL);