Jump to content


Photo

<pre> tags with readfile()

pre readfile preformatted

  • Please log in to reply
2 replies to this topic

#1 zimbabweo

zimbabweo

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 11 March 2013 - 12:49 AM

I can't figure out how to combine readfile() with <pre> tags so that the \n linebreaks in my text file are displayed properly.

 

// works but doesn't print line breaks
echo readfile("filename.txt");

 

// doesn't work -- parse error

echo "<pre>readfile("filename.txt")</pre>";

 

// doesn't work -- parse error
echo "<pre>{readfile("filename.txt")}</pre>\n";

 

Any tips to solve this?



#2 Barand

Barand

    Sen . ( ile || sei )

  • Moderators
  • 17,094 posts
  • LocationCheshire, UK
  • Age:67

Posted 11 March 2013 - 01:00 AM

echo '<pre>';
readfile('filename.txt');
echo '</pre>';
 

 

or

 

echo nl2br(file_get_contents('filename.txt'));

Edited by Barand, 11 March 2013 - 01:11 AM.

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.







moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 zimbabweo

zimbabweo

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 11 March 2013 - 01:05 AM

Barand, that works perfectly!! Many thanks.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users