Jump to content

Replace empty line with a <br> tag from a php read text file...


mits

Recommended Posts

Is there a way i can read a text file and add a br tag where ever there is an empty line.

 

for example;

 

at the moment i have a text file which says

 

"hello 123 456

 

world abc xyz dfdfd

 

dfdf"

 

there is a blank line between the hello and world.  I need a way to add a br tag in between the 2 lines so when it displays it displays exactly as it is in the text file.

 

currently when i print out the contents of the file, it ignores the line breaks.

 

 

so to sum up,

- read an external text file line by line

- replace or add a br tag where ever PHP finds an empty line.

 

thanks

So, did you actually try the suggested solution before you decided it did not work?

 

oops! i have tried it now and it works fine. I used the follwing code.

 

<?php

 

$file = "line_break.txt";

$handle = fopen($file, "r");

 

$string = fread($handle, filesize($file));

 

echo nl2br($string);

 

?>

 

.. and it works exactly how i want.

 

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.