Re: Parsing brackets in text

From: Date: Mon, 13 Nov 2006 13:22:16 +0000
Subject: Re: Parsing brackets in text
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-244544@lists.php.net to get a copy of this message
# dotancohen@gmail.com / 2006-11-13 01:35:44 +0200: > On 13/11/06, Chris <dmagick@gmail.com> wrote: > > > ><?php > >function makeLink($matches) { > > $returnString="<b>" . $matches[1] . "</b>"; > > return $returnString; > >} > > > >$articleText="This is a very [long] string."; > >$articleText=preg_replace_callback('/\[([a-z]+)\]/i' , "makeLink", > >$articleText); > >print $articleText . "\n"; > >?> > > > > > >The callback takes whatever the regular expressions returns (alpha > >characters between [ and ]) and runs it through function "makeLink". > > > >Not sure how that will go with multiple []'s etc in the same string but > >it should get you started. > > > > I didn't know that I had to call the function like that- I don't > remember ever seeing it called that way. It's done this way in all the examples on http://cz.php.net/manual/en/function.preg-replace-callback.php What documentation did you read? > Also, I must google the meaning of the (~+) in the regex. No need to google: http://cz.php.net/manual/en/reference.pcre.pattern.syntax.php Skip the Differences From Perl section. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991

« previous php.general (#244544) next »