Re: Bug in preg_match() ?

From: Date: Sun, 11 Jul 2004 19:22:37 +0000
Subject: Re: Bug in preg_match() ?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-11098@lists.php.net to get a copy of this message
* 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!

« previous php.internals (#11098) next »