Skip to content

Instantly share code, notes, and snippets.

@niravmadariya
Last active June 7, 2018 07:02
Show Gist options
  • Save niravmadariya/cb56821e32fde1be13a1d3c2f68523b2 to your computer and use it in GitHub Desktop.
Save niravmadariya/cb56821e32fde1be13a1d3c2f68523b2 to your computer and use it in GitHub Desktop.
Basic file operations in PHP
<?php
//reading a file...
$myfile = fopen("webdictionary.txt", "r");
echo fgets($myfile);
fclose($myfile);
//Write to a file...
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "This is new File\n";
fwrite($myfile, $txt);
$txt = "This is some Content\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment