Online Shopping : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

63 of 90 people (70%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

I need to read a text file & display the contents on the web page from which the php script executed

Mar 15th, 2008 18:16
ha mo, Philip Olson, Marshall Bowling,


There are many ways to do this.  If you're simply dumping text (and not
processing it) then use readfile()
<?php
    readfile('somefile.ext');
?>
If your file contains valid PHP code and you want it processed, one of
the include functions will do this:
<?php
    include 'somefile.ext';
?>
If you want the contents of the file into a string or an array, use
either file() or file_get_contents():
<?php
    $filename = 'somefile.ext';
    $array_of_lines   = file($filename);
    $string_from_file = file_get_contents($filename);
?>
See also the manual entries for details:
  http://www.php.net/readfile
  http://www.php.net/include
  http://www.php.net/file
  http://www.php.net/file_get_contents
Note that the above functions may also work through HTTP (URLS).
http://www.tantofa.com
http://www.fantofa.com
http://www.mantofa.com
http://www.tanpola.com
http://www.tampola.com
http://www.yamot.com
http://www.mozmar.com
http://www.templatestemp.com