RE: [PHP] Simple String Replace Question

From: Date: Sun, 25 Feb 2001 23:22:54 +0000
Subject: RE: [PHP] Simple String Replace Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41613@lists.php.net to get a copy of this message
That almost works. The two \n in a row are on new lines. So it's \n \n intead of \n\n. If that makes any sense. Jeff Oien > Or you could just do this: > > <?php > $str = "abc\ndefg\n\nxyzpqr\njklmno"; > $str = ereg_replace("([^\n])\n([^\n])", "\\1 \\2", $str); > echo $str; > ?> > > That should give you: > > abc defg\n\nxyzpqr jklmno > > Works by replacing any \n with a space, as long as that \n is not next to > another \n. > > > Cheers > > Simon Garner > >

« previous php.general (#41613) next »