How to include a plain text file in a PHP-Nuke module

21.8. How to include a plain text file in a PHP-Nuke module

A plain text file needs a somewhat different treatment than a HTML file, if it is to be included in a PHP-Nuke module. The reason is that a plain text file lacks the formatting tags that are present in a usual HTML file. If you simply include it as shown in Section 21.5, it will show as a single paragraph, lacking any structure.

Why? Because the "formatting tags" of a plain text file are the newline characters. They will introduce a new line - and a new paragraph. In HTML however, a newline will not suffice, you need a break tag (<br>) to achieve the same effect. Since a PHP-Nuke module is a PHP file, and as such it will be transformed to a HTML file for the visitor, we need to play by the HTML rules if we want our file to be formatted correctly.

Fortunately, the nl2br PHP function (newline to break) comes to our rescue here: it will automatically insert HTML <br /> tags (breaks) before every newline in the text file. Replace

include("path/to/the/html/file"); // <-- CHANGE THIS!

in the code of Section 21.5 with (see another adding module question):

$filename = "path/to/the/text/file"; // <-- CHANGE THIS!
$content_array = file($filename);
$content = implode("", $content_array);
print nl2br($content);

Help us make a better PHP-Nuke HOWTO!

Want to contribute to this HOWTO? Have a suggestion or a solution to a problem that was not treated here? Post your comments on my PHP-Nuke Forum!

Chris Karakas, Maintainer PHP-Nuke HOWTO


Site Info v2.2.2

Last SeenLast Seen
  • elnegro
  • blaci
Server TrafficServer Traffic
  • Total: 377,120,341
  • Today: 467
Server InfoServer Info
  • Feb 21, 2019
  • 12:11 am CET