In PHP, it is really useful to be able to open files and get the information out of them. You can also use files you get the contents of and manipulate them like a template. By using file_get_contents I am able to get the contents of other files, manipulate and output them.
Here are the sources used in this tutorial:
myfile.html
<html><head><title>blah blah</title></head> <body> Testing 123 </body> </html>
toilet.php
<?php /** * @author Kloplop321.com * @copyright 2009 */ echo "toilets are fun"; ?>
tut024.php
<?php //PHP Tutorial 024 //$contents = file_get_contents("toilet.php"); $contents = file_get_contents("myfile.html"); $contents = str_replace("Testing 123","Eat my shorts", $contents); echo $contents; ?>
November 13th, 2009 at 5:57 am
[...] the single function available in the latest PHP build. If you want to refer back to the previous tutorial where I demonstrated loading files, you can see how these two pretty much go together. You need [...]