Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11098 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55144 invoked by uid 1010); 11 Jul 2004 19:10:27 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 54836 invoked from network); 11 Jul 2004 19:10:25 -0000 Received: from unknown (HELO took.shire) (68.126.141.9) by pb1.pair.com with SMTP; 11 Jul 2004 19:10:25 -0000 Received: (qmail 88635 invoked by uid 1001); 11 Jul 2004 19:22:37 -0000 Date: Sun, 11 Jul 2004 19:22:37 +0000 To: PHPdev Message-ID: <20040711192237.GG57216@bagend.shire> Mail-Followup-To: PHPdev References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Subject: Re: [PHP-DEV] Bug in preg_match() ? From: curt@php.net (Curt Zirzow) * 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: > >
> Warning: Unknown modifier '/' in /home/michael/bug.php on > line 5
> > > 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!