* Thus wrote Michael Spector:
> 
> Hi,
> 
> This script:
> 
> <?
>         $line = "Use operator m// for matching strings";
>         $pattern = "m//";
> 
>         if(preg_match("/$pattern/", $line, $match)) {
>                 print $match[0]."\n";
>         }
> ?>
> 
> outputs the following error:
> 
> <br />
> <b>Warning</b>:  Unknown modifier '/' in <b>/home/michael/bug.php</b> on 
> line <b>5</b><br />
> 
> 
> I thought it should find the match "m//" ...
> 
> Can you say, why search of the ending delimiter in a pattern cannot
> be performed in a simple way, as you can see in the attached patch ?

Because of side effects like this:

  $pattern = "Foo//i";
  if(preg_match("/$pattern", $line, $match)) {

With your patch the preg_match has silently turned into a
caseINsensitve search.

Just use preg_quote($pattern, '/');


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to