19.2 Converting ASCII to HTML


You want to convert your ASCII text files to HTML.

Technique

Use a combination of htmlentities() and nl2br() to convert the document:

 <?php $doc = implode("", file($conversion_file)); $doc = nl2br(htmlentities($doc)); print $doc; ?> 

Comments

The htmlentities() function replaces all special HTML characters such as , , and with the equivalent escape character sequences. The nl2br() function takes all newline characters and inserts a <br> tag (HTML line break). Converting ASCII to HTML is really that simple!



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net