// LOCK_EX will prevent anyone else writing to the file at the same time
// PHP_EOL will add linebreak after each line
$txt = "data-to-add";
$myfile = file_put_contents('logs.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);
// Second option is this
$myfile = fopen("logs.txt", "a") or die("Unable to open file!");
$txt = "user id date";
fwrite($myfile, "
". $txt);
fclose($myfile);
<?php
$file = 'myFile.txt';
$text = "This is my Text
";
file_put_contents($file, $text, FILE_APPEND | LOCK_EX);
// adds "This is my Text" and a linebreak to the end of "myFile.txt"
// "LOCK_EX" prevents anyone else writing to the file at the same time
?>
$log_content="This line is logged on 2020-08-14 09:55:00";
$myfile = fopen("log.txt", "a") or die("Unable to open file!");
fwrite($myfile, $log_content);
fclose($myfile);
$fptr = fopen('myfile2.txt','a');
fwrite($fptr,"hii.. this is appending inside file
")
fclose($fptr);
Code Example |
---|
:: |
:: |
:: |
:: |
Php :: |
:: bind multiple data in one id in php using php using for loop |
Php :: |
Php :: |
:: |
:: |
Php :: |
:: |
:: |
Php :: |
Php :: |
:: |
Php :: |
:: persian error laravel |
:: |
Php :: wordpress get category page title |
Php :: |
:: |
:: |
:: |
:: |
Php :: |
Php :: |
:: |
:: php select page change |
:: |