PHP file_put_contents()函数

PHP file_put_contents()函数

file_put_contents() 函数可以将字符串写入文件。

语法

int file_put_contents ( string filename , mixeddata [, int flags = 0 [, resourcecontext ]] )

如果成功,该函数可以返回写入文件的字符数。如果失败,它可以返回false。

示例1

<?php
   echo file_put_contents("PhpProject/sample.txt" ,"Hello World!");
?>

输出

11

示例2

<?php
   file = "/PhpProject1/sample.txt";
   // The new person to add to the filetest = " Tutorialspoint";
   // using the FILE_APPEND flag to append the content to the end of the file
   // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
   file_put_contents(file,test, FILE_APPEND | LOCK_EX);
   echo "Content has been loaded successfully";
?>

输出

Content has been loaded successfully

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程