Is it possible to always write in the first line using PHP?

3

Well, I want to make PHP always write in the first line in a text file, that is, I want it to never write below or in the text.

Put simply, I want him to write before the texts.

Is it possible?

    
asked by anonymous 13.10.2016 / 02:24

2 answers

4

Yes it is possible, but there is no specific command, if that's what you want to know.

file_put_contents($filename, $data . file_get_contents($filename));

Do not forget to break the line: $data = 'Belezura\n';

    
13.10.2016 / 02:58
1

I believe this is what you want to do:

$nome_arquivo = 'c:\texto.txt';
$arquivo      = file($nome_arquivo);
$arquivo      = implode("\n",$arquivo);
$string_a_ser_inserida = "PROPRIEDADE DE : PABLO MARTINS" . PHP_EOL;
file_put_contents($nome_arquivo , $string_a_ser_inserida . $arquivo);
    
13.10.2016 / 15:04