IHYPRESS PROGRAMMING
PHP programs with code and output for beginners
php logo
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
PHP ❯ Using Files
<11>
<?php /* using files */ $filename = "quotes.txt"; $filevar = fopen($filename, 'w') or die("can't open file"); /* creating - writing */ fwrite ($filevar, "Baseball is ninety percent mental and the other half is physical.\n"); $quote2 = "If you come to a fork in the road, take it.\n"; fwrite ($filevar, $quote2); fclose($filevar); /* appending */ $filevar = fopen($filename, 'a') or die("can't open file"); $quote3 = "It's like deja-vu, all over again.\n"; fwrite ($filevar, $quote3); fclose($filevar); /* reading */ $filevar = fopen($filename, 'r') or die("can't open file"); echo "<div style='font-size:22px;color:#990000;'>"; while (!feof($filevar)) { $quote = fgets ($filevar); echo "<p><i>$quote</i></p>"; } echo "</div>"; fclose ($filevar); /* delete file */ unlink ("quotes.txt"); ?>
Hergestellt in Deutschland / Made in Germany

Baseball is ninety percent mental and the other half is physical.

If you come to a fork in the road, take it.

It's like deja-vu, all over again.

COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland