-
-
/** - * php file programming to write files
- * edit bbs.it-home.org
- */
- //Write file
- $file_path="text.txt";
- if(!file_exists($file_path)){
- echo "The file does not exist";
- exit();
- }
- //"a+" Append "w+" to the end of the file and rewrite
$fp=fopen($file_path,"w+ ");
- $con="rnHello";
- for($i=0;$i<10;$i++){
- fwrite($fp,$con);}
fclose($fp); - ?>
-
Copy the code
Method 2, write the file through the file_put_contents function
-
-
- //Second way to write files
- $file_path="text.txt";
- $content="hello,worldrn";
-
//The default for writing a string to a file is [FILE_USE_INCLUDE_PATH] "w+" re-write
- file_put_contents($file_path,$content,FILE_APPEND);
echo "OK" ;
- ?>
-
Copy code
|