Tools, FAQ, Tutorials:
Opening a File for Writing in PHP
How To Open a File for Writing in PHP?
✍: FYIcenter.com
If you want to open a new file and write date to the file, you can use the fopen($fileName, "w") function. It creates the specified file, and returns a file handle. The second argument "w" tells PHP to open the file for writing. Once the file is open, you can use other functions to write data to the file through this file handle. Here is a PHP script example on how to use fopen() for writing:
<?php
$file = fopen("/temp/todo.txt", "w");
fwrite($file,"Download PHP scripts at dev.fyicenter.com.\r\n");
fclose($file);
?>
This script will write the following to the file:
Download PHP scripts at dev.fyicenter.com.
Note that you should use "\r\n" to terminate lines on Windows. On a Unix system, you should use "\n".
⇒ Appending Data to the End of a File in PHP
⇐ Opening a file for Reading in PHP
2016-12-02, ∼3109🔥, 0💬
Popular Posts:
How to start Docker Daemon, "dockerd", on CentOS systems? If you have installed Docker on your CentO...
How to Install Docker Desktop 2.5.0 on Windows 10? You can follow this tutorial to Install Docker De...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
How to use the "@{...}" expression block in Azure API Policy? The "@{...}" expression block in Azure...
FYIcenter.com Online Tools: FYIcenter JSON Validator and Formatter FYIcenter JSON to XML Converter F...