Re: replacing \n with <br>

From: Date: Fri, 06 Sep 2002 16:05:01 +0000
Subject: Re: replacing \n with <br>
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-115504@lists.php.net to get a copy of this message
David T-G wrote: > I've never had problems with doing: $foo = "I don't like\nnewlines"; $foo = ereg_replace( "\n", '<br />', $foo ); Cheers, Rob. > Hi, all -- > > I have a php script which writes comments out to a file in the format > > field@@comment > field@@comment > ... > > and everything has worked delightfully -- until someone put in a newline > in one of the items and now we have > > field@@com > ment > field@@comment > ... > > and things break. I read the file, line by line, and parse on @@ as my > separator, so anything after a newline is lost. > > I thought I'd just replace that newline with a <br> since that's what the > user really wants, but I can't get rid of the \n while I'm at it; through > various attempts at directly replacing or using variables or such like > > preg_replace("/\n/","<br>",$mydatastring) ; > preg_replace("/$newline/","$linebreak",$mydatastring) ; > > I get mixed results of > > field@@com<br> > ment > > or > > field@@com > <br>ment > > but in no case have I managed to get > > field@@com<br>ment > > which is what I want. > > Is there a way to turn off the recognition of \n as an end of line and > instead operate on the entire $mydatastring? > > TIA & 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 (#115504) next »