Re: RegExp Tags and Text Oh My

From: Date: Mon, 17 Jul 2000 17:20:07 +0000
Subject: Re: RegExp Tags and Text Oh My
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6948@lists.php.net to get a copy of this message
On Mon, 17 Jul 2000, Some Guy wrote: > Ok I have a couple of unrelated scripts but 2 problems > that are related. I am using PHP4 > > First problem grabbing text between 2 tags looks like this > > <SOMETAG>TEXT</SOMETAG> Untested code, but something like this: $eregi("<sometag>([^<]+)</sometag>",$contents,$regs); $regs[1] should be = "TEXT" BTW [^<]+ means 'any character except "<", more than zero times (one or more) > How do I capture the text between the 2 tags into a variable > the text might span more than 1 line but will usually only > be 1 or 2 words but could be 100s of words > > Problem 2. I have a variable that has some stuff in it and > want to place it in place of a tag set. > > This is sort of a template. I have a html file that has > a set of tags and want to repalce the set of tags and > anything between them with the contents of the variable > as Im presenting it to the browser client. > > variable contents > $hello = "Hello World<BR>\n"; > > contents of html file > <HTML> > <BODY> > <SOMETAG>SOMETEXT</SOMETAG> > </BODY> > </HTML> > > I want the browser to recieve > <HTML> > <BODY> > Hello World<BR> > </BODY> > </HTML> > > without changing the contents of the html file $contents = $eregi_replace("<sometag>SOMETEXT</sometag>",$hello",$contents); Hans Anderson ~ me@hansanderson.com PO Box 426, Missoula, MT 59806 | PHP, Search Engines, SQL (800)397-9116 / (406)549-6524 | Databases, Flash Multimedia, http://www.hansanderson.com | Killer Audio Production, http://www.goofiness.com | Minty Fresh Breath.

« previous php.general (#6948) next »