Re: ereg_replace()
| From: | Jeff Warrington | Date: | Thu, 07 Sep 2000 22:37:39 +0000 |
| Subject: | Re: ereg_replace() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-15792@lists.php.net to get a copy of this message | ||
In article
<Pine.LNX.4.21.0009062128300.15883-100000@northface.intercarve.net>,
dvogel@intercarve.net ("Drew P. Vogel") wrote:
not 100% sure this is your answer, but with ereg or eregi, if you
use paranthesis to store values, you need to use the following
syntax:
$matchRegex = "\[(.) (.)+ \]";
while (eregi($matchRegex,$templateLine,$regs)) {
$templateLine = eregi_replace($matchRegex, filter($regs[2],$regs[1]),$templateLine);
}
the third optional parameter of ereg is the name of a variable that
will contain an array of the parathesisized patterns. The [0] index
stores the entire string, so the first () would be accessed via the
[1] offset of the array.
hope this helps,
Jeff
> 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
>
>