The following code is an example to write to a file line-by-line:
if(file_exists("files/john") && is_dir("files/john"))
$myFile = "files/john/msg.txt";
else
{
mkdir("files/john");
$myFile = "files/john/msg.txt";
}
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = date("d-M-Y H:i:s").' : '.trim($_POST['msg']);
fwrite($fh, $stringData."
");
fclose($fh);
Read a file line-by-line:
$filename = "test.txt";
$fp = fopen( $filename, "r" ) or die("Couldn't open $filename");
while ( ! feof( $fp ) ) {
$line = fgets( $fp, 1024 );
print "$line<br>";
}
if(file_exists("files/john") && is_dir("files/john"))
$myFile = "files/john/msg.txt";
else
{
mkdir("files/john");
$myFile = "files/john/msg.txt";
}
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = date("d-M-Y H:i:s").' : '.trim($_POST['msg']);
fwrite($fh, $stringData."
");
fclose($fh);
Read a file line-by-line:
$filename = "test.txt";
$fp = fopen( $filename, "r" ) or die("Couldn't open $filename");
while ( ! feof( $fp ) ) {
$line = fgets( $fp, 1024 );
print "$line<br>";
}
Comments
Post a Comment