Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Une fonction appelée file_append_contents()

<?php

// appends the text to the end of the end of the file
file_put_contents($file, $text, FILE_APPEND);

// appends the text to the end of the end of the file
$fp = fwrite($file, 'a');
fwrite($fp, $text);

file_put_contents() peut ajouter des données à la fin d’un fichier, avec l’option FILE_APPEND.

file_put_contents() garde le fichier ouvert le moins longtemps possible, et l’opération est atomique. C’est préférable à l’écrasement de l’intégralité du fichier ; et c’est souvent mieux que fopen(), qui maintient le fichier ouvert jusqu’à la fin de l’exécution.

See Also

PHP Features

Last updated: 22 October 2026