1$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
2fwrite($myfile, "Content to write to file");
3fclose($myfile);
1$myFile = "testFile.txt";
2$fh = fopen($myFile, 'w') or die("can't open file");
3$stringData = "Bobby Bopper\n";
4fwrite($fh, $stringData);
5$stringData = "Tracy Tanner\n";
6fwrite($fh, $stringData);
7fclose($fh);
8
1// if not file is there then automatic create and write inside it.
2$fptr = fopen('myfile.txt','w');
3fwrite($fptr,"i am writing file in this\n");
4fwrite($fptr,'writing another line.');
5fclose($fptr);
1<?php
2$myfile = fopen("file_name.txt", "w") or die("Unable to open file!");
3$txt = "Hello world\n";
4fwrite($myfile, $txt);
5$txt = " Php.\n";
6fwrite($myfile, $txt);
7fclose($myfile);
8?>