I'm trying to display the contents of a text file in original format on a...

joegats916

New member
...webpage using PHP, please help? I'm trying to setup a webpage, with blocks of text that are pulled from a series of text files in a directory hosted along with the webpage. I've been experimenting with php codes to echo the text which has worked great, (i can get the text to show up on the webpage) but it's losing it's format. That is to say, that I want each unindented paragraph block to display one after another the they they do in the text file without having to use any special codes in the text file itsself.

ie
contents of txtfile.txt

words words words

words words words

i want those two lines of words to show up exactly like that with the space between them as if i was using the html <p> command.

I know this is a tough one, any ideas?
Farisoft, that script worked to display the text, but not to retain the formatting of the file. the text appears without break instead of in grouped paragraphs the way they are in the text file
 
<?Php
$file = $_SERVER['DOCUMENT_ROOT'] . "/text.txt"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);

echo $string;
?>
 
Back
Top