# \[PHP\] fclose help

**URL:** <https://forum.kirupa.com/t/php-fclose-help/115129>\
**Category:** Uncategorized\
**Created:** [July 5, 2004, 9:54pm UTC](https://forum.kirupa.com/t/php-fclose-help/115129 "2004-07-05T21:54:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joso](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@joso](https://forum.kirupa.com/u/joso)\
**Post date:** [July 5, 2004, 9:54pm UTC](https://forum.kirupa.com/t/php-fclose-help/115129/1 "2004-07-05T21:54:45Z")

</div>

hi…

i’m trying to sort out this text area that adds text to a textfile called test.txt…im just using the one text box so i want it so when you hit enter to start a new line in the text box it inserts a linebreak when you’ve submitted the text into the textfile…

i also want each post to just wipe over the last…so theres only ever one lot of text in the text file at a time…🙂 thanks

heres the code im using for the php file to add text:

```php
<?php
$filename = 'test.txt';
$somecontent = '<table width="90" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="6" align="right" valign="middle"></td>
    <td width="84" align="left" valign="top"><strong>' . date('d.m.y') . '</strong></td>
  </tr>
  <tr>
    <td align="right" valign="top">-</td>
    <td align="left" valign="top">' . nl2br($_POST['updates']) . '</td>
  </tr>
</table>';

if (is_writable($filename)) {
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   
   echo "Success, Updates were changed!";
   
   fclose($handle);
                   
} else {
   echo "The file $filename is not writable";
}
?>

```

and if you want to see the text box…its here :

[http://www.band-central.net/atreyu/test/index.php](http://www.band-central.net/atreyu/test/index.php)

and the post gets added to this page

[http://www.band-central.net/atreyu/home.php](http://www.band-central.net/atreyu/home.php)

on the left side in the ‘updates’ box

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 6, 2004, 2:21am UTC](https://forum.kirupa.com/t/php-fclose-help/115129/2 "2004-07-06T02:21:45Z")

</div>

maybe this will help

```php

$text_post = nl2br($somecontent);

```

use $text in the fwrite(…) function instead of $somecontent
