RE: [PHP] ereg_replace()

From: Date: Thu, 07 Sep 2000 03:01:35 +0000
Subject: RE: [PHP] ereg_replace()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-15645@lists.php.net to get a copy of this message
If the filter() function is being called first, with the arguments interprected first, then how does it return "L"? The only way the $flags argument to filter() could hold the value of "L" to be returned is if ereg_replace() passed it as the second parenthesised token. The script is meant to replace the text between [L and ] with a corresponding value. This is why it is supposed to return "L" with 'return $flags;'. --Drew Vogel On Thu, 7 Sep 2000, WILSON, Nick wrote: > It's not a bug, it's the way you are using ereg_replace. The second > argument is the replacement text (or reg exp). So in your case, the > filter function is first called with arguments \1 and \2 (the first > \ will be an escape character). > > To do what you want to do, you will have to assign the matched text > to variables and then call filter, ie something like > > $templateLine = eregi_replace( $matchRegex, "\\1:\\2", $templateLine ); > list($phase, $flag) = split (":", $templateLine); > filter("phase", "$flag" ); > > > > -----Original Message----- > > From: Drew P. Vogel [mailto:dvogel@intercarve.net] > > Sent: Thursday, 7 September 2000 12:40 > > To: php-general@lists.php.net > > Subject: [PHP] ereg_replace() > > > > > > Hi. I am having a problem using a function as the second argument to > > ereg_replace(). > > > > This is an excerpt from my code. Within the filer() function, the > > paramaters act differently in different functions. > > > > BEGIN EXCERPT > > > > $matchRegex = "\[(.) (.)+ \]"; > > while ( eregi( $matchRegex, $templateLine ) ) { > > $templateLine = eregi_replace( $matchRegex, filter( > > "\\2", "\\1" ), $templateLine ); > > } > > > > function filter ( $phrase, $flags ) { > > > > END EXCERPT > > > > 'echo $flags;' outputs "\1", where 'return $flags;' returns > > "L" (it is > > supposed to return "L"). Is this a bug in php? Am I > > misunderstanding the > > use of \\n? > > > > --Drew Vogel > > > > > > -- > > 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 (#15645) next »