“PHP Appender para arquivar” Respostas de código

PHP Appender para arquivar

// 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, "\n". $txt);
fclose($myfile);
MeVyom

PHP salvar matriz para arquivar

$arr1 = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
file_put_contents("array.json",json_encode($arr1));
# array.json => {"a":1,"b":2,"c":3,"d":4,"e":5}
$arr2 = json_decode(file_get_contents('array.json'), true);
$arr1 === $arr2 # => true
Mobile Star

Anexando o arquivo txt de php

$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);
Embarrassed Eagle

Respostas semelhantes a “PHP Appender para arquivar”

Perguntas semelhantes a “PHP Appender para arquivar”

Mais respostas relacionadas para “PHP Appender para arquivar” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código