I'm reading from a file that has line breaks as in spacing items like this:
Item1
ITEM2
ITEM3
But it comes out like Item1ITEM2 ITEM3
Here is the Code:
if (!$file_handle = fopen($file,"r")) { echo "Cannot open file."; }
if (!$file_contents = fread($file_handle, filesize($file))) { echo "Cannot retrieve file contents."; }
else { echo "$file_contents\r\n"; }
fclose($file_handle);
If some one could help me I'd appreciate it a LOT!!!
THANK YOU
Reading File with Line Breaks?
Moderator: General Moderators
If you are trying to output this in HTML you just need to change the \r\n to a <br>.
Instead of
put
Instead of
Code: Select all
<?php
else { echo "$file_contents\r\n"; }
?>Code: Select all
<?php
else { echo "$file_contents<br>"; }
?>This will replace all of the line breaks in the file with <br> tags.
Code: Select all
<?
if (!$file_handle = fopen($file,"r")) { echo "Cannot open file."; }
if (!$file_contents = fread($file_handle, filesize($file))) { echo "Cannot retrieve file contents."; }
else { echo nl2br($file_contents); }
fclose($file_handle);
?>