RE: [PHP-GENERAL] Re: [PHP3] ereg_replace

From: Date: Tue, 20 Jun 2000 19:39:23 +0000
Subject: RE: [PHP-GENERAL] Re: [PHP3] ereg_replace
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-2344@lists.php.net to get a copy of this message
Hi Chris, At 03:18 PM 6/20/00 -0400, Chris Sano wrote:
Zak, was looking at the snipet of code you posted on the mailing list and there's one part that is new to me.. and was hoping you could explain it to me..
         $contents = ereg_replace
           (
                 '([^[:alpha:]])LONG_FLOORVAR([^[:alpha:]])',
                 "\\1$long_floorvar\\2",
                 $contents
           );
What is the \\1$long_floorvar\\2", portion supposed to do? What do the 1 and 2 stand for?
Whenever you place a regular expression inside a pair of parenthesis any matches for that expression are placed into a special buffer. The captured matches can be accesses by using \\1, \\2, \\3, etc... inside the replace argument. There can be up to 10 items in the buffer. To find the position of a particular match in the buffer, count the opening parenthesis from left to right in your expression. HTH, Zak Greant "I am rather like a mosquito in a nudist camp: I know what I ought to do, but I don't know where to begin." - Stephen Bayne

« previous php.general (#2344) next »