Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

85 users online



displaying a text file line by line

displaying a text file line by line

Currently viewing this thread: 1 (0 members and 1 guests)


schoi

schoi

funny and cheeky
Status: Offline!

displaying a text file line by line

Hi
basically i have a log file I want to display on my webpage. I thought between lines it's just a new line on linux and a carriage return and newline on windows. Therefore my delimiter is the LF character right? then why doesn't this work
$data = explode('\n',$data); Am using linux so it's just a line feed.

nertman

nertman

lurker
Status: Offline!

well you have to do <br> if your viewing it as an html or php page... if it's not a plain txt so <br>\n

Jeff

Jeff

loves kitties and cuddles
Status: Offline!

"One example is the PHP constant PHP_EOL, which will produce either '\r\n' or '\n' appropriate to the operating system the program is executed on.[3]" - http://en.wikipedia.org/wiki/Newline

Quick script:

Code:

<?php
$exploded_data = explode(PHP_EOL, $data);
foreach ($exploded_data as $line) {
echo $line . "<br />";
}
?>

___________________

I've got a girlfriend! WOOT.

Motorspin

Motorspin

Neverside Newbie
Status: Offline!

The reason your code didn't work is because you're using single quotes instead of double quotes. If you use single quotes, PHP thinks of '\n' as a literal (aka looks for the characters \n, not the escape sequence "\n"). If you use double quotes, PHP will substitute \n for the newline escape sequence.

i.e. <?php $data = explode("\n",$data); ?>

Hopefully that makes sense.

___________________

Travis Farrell
http://motorspin.com/stuff/images/avasig/m_enterprisesig.gif

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0168 seconds.