(SOLVED) Re: [PHP] replacing \n with <br>
| From: | David T-G | Date: | Fri, 06 Sep 2002 16:44:39 +0000 |
| Subject: | (SOLVED) Re: [PHP] replacing \n with <br> | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-115520@lists.php.net to get a copy of this message | ||
Rob, et al --
..and then Robert Cummings said...
%
% David T-G wrote:
% >
% > ...and then Robert Cummings said...
% > %
..
% > % $foo = str_replace( "\n", '<br />', $foo );
% > %
% > % That one work for you? It's more efficient too.
% >
% > Actually, no. I thought about listing all of the things I had tried (and
..
% > well as the $fin and $fout separation. I always have the newline left
% > behind.
..
%
% *ACK* Stoopid microsoft... it's the "\r" character I bet.
That was it, or at least sort of. Thank heavens I always test before I
post, because I was going to smugly comment that I'm using freebsd *but*
I tried switching to \r and noticed that the added <br> moved from one
line to the other. So I whipped up
$fout = ereg_replace("(\n|\r)+","<br>",$fin) ;
and it works -- there must actually be \r\n there -- and I'll work
backwards from there (I'll use an expression like the above to robustly
handle by-god-anything that comes in!) to get rid of these temp variables.
%
% Cheers,
% Rob.
Thanks a *bunch*!
:-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!