Home / PHP Tips Generated By ChatGPT / Using fopen() for Reading and Writing Files in PHP Open a file for reading or writing. Source Code $file = fopen("test.txt", "w"); if ($file) { fwrite($file, "Hello, World!"); fclose($file); } else { echo "Unable to open file!"; }