This article introduces the steps to write files in PHP programming. Friends who need it can learn it.
In PHP, writing files generally requires the following steps: 1. First, determine the content to be written to the file $content = ‘Hello’; 2. Then, open the file (the system will automatically create this empty file) //假设新建的文件叫file.txt,而且在上级目录下。w表示‘写文件’, $fp下面要用到,表示指向某个打开的文件。 $fp = fopen(’../file.txt’, ‘w’); Copy after login 3. Write the content string to the file //$fp tells the system the file to be written, and the written content is $content. fwrite($fp, $content); //文件写入 Copy after login 4. Close the file fclose($fp); Note: PHP5 provides a more convenient function file_put_contents, Therefore, the above four steps can be reduced to: <?php $content = ‘你好’; file_put_contents(’file.txt’,$content); Copy after login |