WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: edpnjax on January 18, 2008, 08:33:47 PM

Title: Read in a text file
Post by: edpnjax on January 18, 2008, 08:33:47 PM
I had a need with WxSim to read in a text file to an html/php page. Sounds simple.... (ok, maybe to some of you PHP guru's) problem was the text file changes with every WxSim run and contains no html tags or formatting, so just doing a simple include just turned it into one really long line. I also did not want to turn this simple task into some convoluted nightmare!

After testing this, testing that, Google'in this and that I finally came up with a simple solution to read in a raw text file and keep the text formatting. Hope it saves some time or helps out.

Quote
<?php
   echo "<pre>\n"; @readfile("./path/to/filename.txt"); echo "</pre>\n";
 ?>