Re: preg_replace question

From: Date: Sat, 20 Sep 2003 21:02:22 +0000
Subject: Re: preg_replace question
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-163303@lists.php.net to get a copy of this message
Finaly I got the solution. Replace all line breaks by <br /> but not after a html headline (<h1>..</h1>) $text = preg_replace("/(?<!h[1-6]\>)\r\n/","\\1<br />",$text); ----- Original Message ----- From: "Armand Turpel" <armand@a-tu.net> To: <php-general@lists.php.net> Sent: Saturday, September 20, 2003 7:34 PM Subject: Re: [PHP] preg_replace question > Hi Jim , > The problem with your proposition is that the preg_replace do not replace > </h1>\r\n to </h1><br /> > thats good, > but also not this: > testh4>\r\n > > and thats not what I expect from. > > > atur > > > > > > > ----- Original Message ----- > From: "Jim Lucas" <phplist@zonedzero.net> > To: "Armand Turpel" <armand@a-tu.net>; <php-general@lists.php.net> > Sent: Saturday, September 20, 2003 5:37 PM > Subject: Re: [PHP] preg_replace question > > > > $arr = array("/([^\<][^\/][^h][^1-6].{1}[^\>])\r\n/", > > "/([^\<][^\/][^h][^1-6].{1}[^\>])\r/", > > "/([^\<][^\/][^h][^1-6].{1}[^\>])\n/", > > ); > > > > $text = preg_replace($arr,"\\1<br />",$text); > > > > you might try this and see how well it works. > > > > Jim Lucas > > > > > > ----- Original Message ----- > > From: "Armand Turpel" <armand@a-tu.net> > > To: <php-general@lists.php.net> > > Sent: Saturday, September 20, 2003 8:21 AM > > Subject: [PHP] preg_replace question > > > > > > > I need the following replace function: > > > Replace all line breaks to <br> but not if a line break comes after an > > </h1> > > > or </h2> or .... </hx> > > > > > > > > > Currently I use this preg_replace but it's not good enough for all > > > situations. > > > > > > $text = preg_replace("/([^\<][^\/][^h][^1-9].{1})\r\n/","\\1<br > > />",$text); > > > > > > > > > ???? > > > > > > Thanks > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > >

« previous php.general (#163303) next »