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?

59 of 66 people (89%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do I include pre-formatted text into a PHP page?

Jan 2nd, 2009 00:25
Venus venui, healthy man, sheana krat, dman, Vimal Pratap, raun siegal, Articles Hosting, Philip Olson, Johan Naudé,


There are many ways to insert a text file into PHP.  It's common to use
include() for this purpose.  include can be read about in the PHP 
manual
here (many examples exist):
  http://www.php.net/include
  include 'filename';   : Includes and evaluates the 
                          specified file.
The file is evaluated, so PHP code is evaluated as PHP code.  PHP code
is written within valid PHP tags, most commonly <?php ?>.
In the example below, we'll preserve whitespace in HTML by using 
<pre>.   
  <pre>
    <?php 
      include 'some/file.txt'; 
    ?>
  </pre>
Or, to open the file up into a variable, consider file().  file opens a
file as an array, each element being a line in that array.  file() is
sexy in that it opens files in one line of code :)  Also see 
fopen/fgets
and Curl.  
An example using file():
  <?php
    $filename = 'afile.txt';
    $lines = file($filename);
    // $lines is an array.  let's print the third line of afile.txt
    print $lines[2];
    // open file as an array, implode that array into a string 
    $file_string = implode('', file($filename));
    // print string, first converting newlines into <br \>'s
    print nl2br($file_string);
  ?>
   Read the PHP Manual for information regarding these functions.
     http://www.php.net/manual/
Another example.  Let's execute a Linux fortune and ouput the results 
to
an HTML page:
  <?php
    $fortune = `fortune`;
    print nl2br($fortune);
  ?>
  fyi: We used ``backticks`` to execute the fortune command on 
       the system.  Read about executing commands in php here:
         http://www.php.net/exec
         http://www.php.net/manual/en/language.operators.execution.php
Also keep in mind that different operating systems have different
"versions" of "newlines":
  \n    = unix
  \r\n  = windows
  \r    = mac
More information on using strings in PHP:
  http://www.php.net/manual/en/language.types.string.php
====
see this article :
softpress.com/kb/article.php?id=715
http://www.healthdothealth.com
http://www.healthxhealth.com
http://www.mesotheliomainmesothelioma.com
http://www.healthfirewall.com
http://www.flathealth.com
http://www.healthbodyguard.com
http://voyage-londres.blogspot.com
http://meine-valentine.blogspot.com
http://calatoriesingapore.blogspot.com/
http://guia-de-saude.blogspot.com
http://valentineideer.blogspot.com
http://gaveideer1.blogspot.com
http://gavoride.blogspot.com
http://resorchile.blogspot.com/
http://reiseschweiz.blogspot.com/