首页 > PHP教程 > PHP常用函数手册 > PHP 文件系统函数

PHP file_put_contents() 函数

 函数原型

/**

 * 把一个字符串写入文件中

 * @link http://php.net/manual/en/function.file-put-contents.php

 * @param string $filename  要写入数据的文件。如果文件不存在,则创建一个新文件。

 * @param mixed $data  要写入的数据。类型是 string,array 或者是 stream 资源

 * @param int $flags [optional]  FILE_USE_INCLUDE_PATH:在 include 目录里搜索文件、FILE_APPEND:如果文件 filename 已经存在,追加数据而不是覆盖、LOCK_EX:在写入时获得一个独占锁

 * @param resource $context [optional]  一个 context 资源

 * @return int  返回写入到文件内数据的字节数,失败时返回FALSE

 * @since 5.0

 */

function file_put_contents ($filename, $data, $flags = null, $context = null) {}

 

函数示例

<?php

echo file_put_contents("a.txt","Hello World!");

?>

关闭
感谢您的支持,我会继续努力!
扫码打赏,建议金额1-10元


提醒:打赏金额将直接进入对方账号,无法退款,请您谨慎操作。