← All built-ins / file_put_contents()

file_put_contents()

file_put_contents(...$args): int

Parameters

NameTypeDescription
$pathstringfile path
$datastringcontent to write
$flagsintPHP_FILE_APPEND to append instead of truncatingoptional

Return value

Number of bytes written.

Example

$n = file_put_contents("/tmp/hphp_doc_demo2.txt", "line1\n");
file_put_contents("/tmp/hphp_doc_demo2.txt", "line2", PHP_FILE_APPEND);
echo $n, "\n", file_get_contents("/tmp/hphp_doc_demo2.txt"), "
";
6
line1
line2

See also

file_get_contents()fopen()fwrite()