Home / Articles / Scripts / Php Script to Append String Into Text File

Php Script to Append String Into Text File

Use a simple PHP script to append string into text file:

<?php
$fn = “file.txt”;
$file = fopen($fn, “a+”);
$size = filesize($fn);
$space.= “n”;
if($_POST[‘addition’]) fwrite($file, $_POST[‘addition’]);

$text = fread($file, $size);
fwrite ($file, $space);
fclose($file);
?>
<form action=”<?=$PHP_SELF?>” method=”post”>
<input type=”text” name=”addition”/><br/>
<input type=”submit”/>
</form>

The file is the text file that you will add to.

Share


Comment on Php Script to Append String Into Text File

Leave a Reply






Contact Us