Display the Contents of a File Using PHP



How to Display the Contents of a File Using PHP

PHP has a built in function to display the contents of a file. This is helpful if you want to update a webpage to reflect some data that is regularly updated or output to a file. It is also helpful if you have access to the web server and it is easier for you to update a text file than it is to edit html. Simply point your webpage to the text file and the contents of the webpage get updated automatically.

Here’s how it works:

<?php
echo file_get_contents('http://brockangelo.com/uptime.txt');
?>

Easy enough. I used to have a message in the footer of this webpage that said “This server has been up for 14 days, 7 hours, 22 minutes.” All that was doing was reading the contents of the text file that got updated every hour.

Related posts:

  1. How to Display Your “Uptime” using Bash
  2. April Fool’s Batch File
  3. Run a Batch File Invisibly
  4. Display Novell Servers Connected to Your Server

Comments