1

How do i make it skip a line (like clicking the enter button) in the file that i am editing? Here is the code:

<?php
$fn="file.txt";
$file=fopen($fn, "a+");
$size=filesize($fn);
if(isset($_POST['submit'])){    
$add=$_POST['addition'];
fwrite($file, $add);
fclose($file);}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="addition" />
<input type="submit" name="submit" />
</form>
user3370114
  • 5
  • 1
  • 7

2 Answers2

1

Use the constant PHP_EOL:

fwrite($file, PHP_EOL);

As long as you're using php 5.0.2 or above it will be available and append an appropriate EOL character.

Durandal
  • 5,575
  • 5
  • 35
  • 49
1

\n can be used to define new line.

PHP:

<?php
    $fn="file.txt";
    $file=fopen($fn, "a+");
    $size=filesize($fn);
    if(isset($_POST['submit'])){    
        fwrite($file, "\n");
    }
    fclose($file);
?>

HTML:

<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="submit" />
</form>

I've posted the answer but I recommend Durandal's answer to use constant PHP_EOL.

Community
  • 1
  • 1
LIGHT
  • 5,604
  • 10
  • 35
  • 78