Skip to content

Instantly share code, notes, and snippets.

@maxixo
Created January 15, 2026 23:23
Show Gist options
  • Select an option

  • Save maxixo/c8523fd806bcef2463d3a7e5257929cb to your computer and use it in GitHub Desktop.

Select an option

Save maxixo/c8523fd806bcef2463d3a7e5257929cb to your computer and use it in GitHub Desktop.
Reading and writing to files in php
<?php
// WRITE to file
$handle = fopen("example.txt", "w");
fwrite($handle, "Hello, this is a test \n");
fwrite($handle, "We are writing to a file in PHP");
fclose($handle);
// READ from file
$handle = fopen("example.txt", "r");
$content = fread($handle, filesize("example.txt"));
fclose($handle);
echo $content;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment