We can easily write text to files using the fwrite() function. However, you must make sure to open file in writable mode before writing.

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Hello\n";
fwrite($fh, $stringData);
$stringData = "Welcome to vn4000\n";
fwrite($fh, $stringData);
fclose($fh);

Related Posts by Categories