Re: replacing \n with <br>

From: Date: Fri, 06 Sep 2002 16:20:10 +0000
Subject: Re: replacing \n with <br>
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-115511@lists.php.net to get a copy of this message
Actually on second thought... and I don't know why I went with the crowd in the first place... I do the following: $foo = "I don't like\nnewlines"; $foo = str_replace( "\n", '<br />', $foo ); That one work for you? It's more efficient too. Cheers, Rob. David T-G wrote: > > Rob, et al -- > > ...and then Robert Cummings said... > % > % David T-G wrote: > % > > % I've never had problems with doing: > % > % $foo = "I don't like\nnewlines"; > % > % $foo = ereg_replace( "\n", '<br />', $foo ); > > I'm afraid I do. Given my code > > $fin = stripslashes(${base64_encode($k)}) ; ### > print "\$fin is .$fin.<BR>\n"; ### > $fout = ereg_replace("\n","<br>",$fin) ; > print "and \$fout is .$fout.<BR>\n"; ### > > (ignore the scary base64 stuff :-) I get > > $fin is .This is the first line. Here is the second line.. > and $fout is .This is the first line. > Here is the second line.. > > in my browser and > > $fin is .This is the first line. > Here is the second line..<BR> > and $fout is .This is the first line. > <br>Here is the second line..<BR> > <br><br> > > in my browser's source window. The newlines are still there. > > Any thoughts? > > % > % Cheers, > % Rob. > > Thanks & HAND > > :-D > -- > David T-G * It's easier to fight for one's principles > (play) davidtg@justpickone.org * than to live up to them. -- fortune cookie > (work) davidtgwork@justpickone.org > http://www.justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf > Qrprapl Npg! > > > -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > Part 1.2Type: application/pgp-signature -- .-----------------. | Robert Cummings | :-----------------`----------------------------. | Webdeployer - Chief PHP and Java Programmer | :----------------------------------------------: | Mail : mailto:robert.cummings@webmotion.com | | Phone : (613) 731-4046 x.109 | :----------------------------------------------: | Website : http://www.webmotion.com | | Fax : (613) 260-9545 | `----------------------------------------------'

« previous php.general (#115511) next »