Click to See Complete Forum and Search --> : Replacing \n with <br>


deep
08-29-2003, 09:35 AM
Hi :)

I wrote a small text in a file called text.txt. The text reads something like this:


Hello there!

How are you?
Im fine!


But when I print this file on the screen i see the text placed in one line like this:


Hello there!How are you?Im fine!


So I was thinking maybe I could replace all the \n in the text file with a <br> ?
How can I do this? Or is there a better solusuoin?

THX!

Khalid Ali
08-29-2003, 09:43 AM
I am not very well versed in PHP how ever,Here is what I can sugges.

When a fileis read the file ointer already knows where is the linbreak in the file,so you don't have to worry about that.just read the file using

fgets

and after every new line append the line with <br/>

I am sure you are already familiar with file system functions...

if not then visit resource.

http://www.php.net/manual/en/ref.filesystem.php

Kr|Z
08-29-2003, 09:53 AM
$string = ereg_replace("\n", "<br>", $string);

pyro
08-29-2003, 10:37 AM
Just use nl2br() (http://www.php.net/nl2br)...

deep
08-29-2003, 10:41 AM
Cool, Thanks.

pyro
08-29-2003, 10:47 AM
Can't speak for everyone, but I was happy to help, as always... :)