RE: [PHP] ereg_replace question

From: Date: Thu, 12 Oct 2000 05:11:36 +0000
Subject: RE: [PHP] ereg_replace question
Groups: php.general 
Request: Send a blank email to php-general+get-19748@lists.php.net to get a copy of this message
Greetings Master, maybe something like ereg_replace("/<cmt ([^>]?)(.*)</cmt>/","<i>\\1 comments: \\2</i>",$string) If possible, don't use brackets ( ) around the whole reg exp, it gets confusing. I've used / ([^>]?) means match every character that is NOT a > with the ? at the end meaning match only 0 or 1 times, hence it won't be greedy and keep matching more text until another > on the same line. (Not tested) Nick > -----Original Message----- > From: The Master [mailto:kschmit@new.rr.com] > Sent: Thursday, 12 October 2000 14:57 > To: php-general@lists.php.net > Subject: [PHP] ereg_replace question > > > Okay-here's a puzzle-I want to be able to do "custom tag > replacement", which would take text like the following: > > <cmt The Master>This is a comment</cmt> > > and return > > <i>The Master comments: This is a comment</i> > > I thought this would do it: > > ereg_replace("(<cmt (.*)>(.*)</cmt>)","<i>\\2 comments: > \\3</i>",$string) > > but it doesn't. It also COMPLETELY fails on text that contains > <b>...</b> within the \\3 section, ie: > > <cmt The Master>This is <b>a</b> comment</cmt> > > This blows up with the following results: > > <i>The Master>This is <b>a</b comments: comment</i> > > I'd really prefer this format for the tags anyway but > couldn't figure it > out (I suck at regexes, yeah yeah :-) > > <cmt "The Master">some text</cmt> > > Any ideas/help/enlightenment??? > > I'm running PHP 4.0b3 on Red Hat 6.1. > --------------------------------------------- > The Master (Keith Schmit) master@thehaus.net > The Haus: http://www.thehaus.net/ > Personal WWW: http://www.thehaus.net/~master/ > --------------------------------------------- > Cry HAVOC, and let slip the dogs of War. > --- Shakespeare, Julius Caesar > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > >

« previous php.general (#19748) next »