Re: regular expression

From: Date: Mon, 09 Oct 2000 08:54:57 +0000
Subject: Re: regular expression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19164@lists.php.net to get a copy of this message
>>>>> "Matthew Leverton" == "php@aeroinc net" >>>>> <php@aeroinc.net> writes: > I need to do a find & replace, and have been unable to get one part > of it working. Let's say I have the text: > line 1 > line 2 > [code] > line a > line b > [/code] > line 3 > It should be converted into: > line 1<br> > line 2<br> > <pre> > line a > line b > </pre> > line 3<br> > I want to convert all new lines to <br>'s, unless it falls within > the [code] tag. This for a forum that allows people to = use a > pseudo html language to markup their posts. The [code] tages are > translated to <pre>'s, but Netscape then double sp= aces, because > the <pre> (by nature) treats the new line as a <br> and then the > nl2br() function adds a <br> as well. It w= orks fine on IE, but > I'd rather it look proper on all browsers. If you're willing to pipe your text through sed, this little script will do exactly what you asked for in one pass. sed -e '/\[code\]/,/\[\/code\]/!s/$/<br>/;s/\[\(\/*\)code\]/<\1pre>/' -robin -- Robin Vickery............................................... Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK Email: robin@planet-three.net Phone: +44 (0)870 729 5444

« previous php.general (#19164) next »