
March 18th, 2008
05:17 PM
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.

March 21st, 2008
03:51 AM
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

June 6th, 2008
06:33 PM
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:
<?php
$exploded_data = explode(PHP_EOL, $data);
foreach ($exploded_data as $line) {
echo $line . "<br />";
}
?>
___________________
I've got a girlfriend! WOOT.

June 24th, 2008
10:09 AM
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
