Jump to content

Line break using fwrite


graham23s

Recommended Posts

Hi Guys,

 

how do i do a line break when writing to a text file? i tried:

 

  ## referer
  $ref = $_SERVER['HTTP_REFERER'];
  $file = "referrer.txt";
  $fh = fopen($file, 'w');
  $stringtowrite = $ref;
  fwrite($fh, $stringtowrite);
  $linebreak = ("<br />----------------------------------------<br />");
  fwrite($fh, $linebreak);

 

but this actually prints the br tage.

 

thanks for any help

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/82073-line-break-using-fwrite/
Share on other sites

ah thanks guys so would this be ok:

 

<?php
  $ref = $_SERVER['HTTP_REFERER'];
  $file = "sitestats.txt";
  $fh = fopen($file, 'w');
  $stringtowrite = $ref;
  fwrite($fh, $stringtowrite);
  $linebreak = ("\n");
  fwrite($fh, $linebreak);
?>

You can just concatenate the newline character to string you're writing when you write it:

<?php
<?php
  $ref = $_SERVER['HTTP_REFERER'];
  $file = "sitestats.txt";
  $fh = fopen($file, 'w');
  fwrite($fh,$ref . "\n");
?>

 

Ken

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.