PHP/File Directory/Text File Write

Материал из Web эксперт
Перейти к: навигация, поиск

How to add text to the file

   <source lang="html4strict">

<?php

 $myfile = "./test.txt";
 $openfile = fopen ($myfile,"a") or die ("Couldn"t open the file");
 fwrite ($openfile,"Have a nice day! \n");
 fclose ($openfile);
 $openfile = fopen ($myfile,"r") or die ("Couldn"t open the file");
 $file_size=filesize($myfile);
 $file_contents = fread ($openfile,$file_size);
 $msg ="$file_contents";
 fclose ($openfile);
 echo $msg;

?>

      </source>
   
  


Write string to text file

   <source lang="html4strict">

<?php

  $subscriberInfo = "g@wbex.ru";
  $fh = fopen("./text.txt", "at");
  fwrite($fh, $subscriberInfo);
  fclose($fh);

?>

      </source>