Here is my code. I don't know why I am not getting any thing on page.Suggest me a mode in which if I want to run my code everytime, it should append at the end. and i should also be able to read from it
<?php
$a=fopen("Welcome.txt","a+");
fwrite($a, "abc");
echo fgets($a);
fclose($a);
?>
You are using the wrong mode for fopen.
$a = fopen("Welcome.txt","r");
var_dump($a);
a+
will "Open for reading and writing" and "If the file does not exist, attempt to create it".
Instead of using fgets
use file_get_contents()
and file_put_contents()
instead of fwrite
IMO it's a lot cleaner and easier to understand.