Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67324 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12298 invoked from network); 7 May 2013 05:27:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 May 2013 05:27:40 -0000 Authentication-Results: pb1.pair.com header.from=remi@fedoraproject.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=remi@fedoraproject.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fedoraproject.org from 212.27.42.5 cause and error) X-PHP-List-Original-Sender: remi@fedoraproject.org X-Host-Fingerprint: 212.27.42.5 smtp5-g21.free.fr Linux 2.6 Received: from [212.27.42.5] ([212.27.42.5:44385] helo=smtp5-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/2C-22863-9C098815 for ; Tue, 07 May 2013 01:27:39 -0400 Received: from dixsept.famillecollet.com (unknown [82.241.130.121]) by smtp5-g21.free.fr (Postfix) with ESMTP id B6E02D48047 for ; Tue, 7 May 2013 07:27:30 +0200 (CEST) Message-ID: <518890C1.7030403@fedoraproject.org> Date: Tue, 07 May 2013 07:27:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130403 Thunderbird/17.0.5 MIME-Version: 1.0 To: PHP Internals References: In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback From: remi@fedoraproject.org (Remi Collet) Le 04/05/2013 14:39, Laruence a écrit : > with this patch, preg_replace_callback will call user callback with two > arguments, the first one is the same, the second is the regex key if the > regex is an array or NULL if the regex is a string. Here is another example from a real case (Horde_Date) return preg_replace( array('/%b/e', '/%B/e', '/%C/e', '/%([-#]?)d/e', '/%D/e', '/%e/e', '/%([-#]?)H/e', '/%([-#]?)I/e', '/%([-#]?)m/e', '/%([-#]?)M/e', '/%n/', '/%p/e', '/%R/e', '/%([-#]?)S/e', '/%t/', '/%T/e', '/%x/e', '/%X/e', '/%y/e', '/%Y/', '/%%/'), array('$this->strftime(Horde_Nls::getLangInfo(constant(\'ABMON_\' . (int)$this->_month)))', '$this->strftime(Horde_Nls::getLangInfo(constant(\'MON_\' . (int)$this->_month)))', '(int)($this->_year / 100)', 'sprintf(\'%\' . (\'$1\' ? \'\' : \'02\') . \'d\', $this->_mday)', '$this->strftime(\'%m/%d/%y\')', 'sprintf(\'%2d\', $this->_mday)', 'sprintf(\'%\' . (\'$1\' ? \'\' : \'02\') . \'d\', $this->_hour)', 'sprintf(\'%\' . (\'$1\' ? \'\' : \'02\') . \'d\', $this->_hour == 0 ? 12 : ($this->_hour > 12 ? $this->_hour - 12 : $this->_hour))', 'sprintf(\'%\' . (\'$1\' ? \'\' : \'02\') . \'d\', $this->_month)', 'sprintf(\'%\' . (\'$1\' ? \'\' : \'02\') . \'d\', $this->_min)', "\n", '$this->strftime(Horde_Nls::getLangInfo($this->_hour < 12 ? AM_STR : PM_STR))', '$this->strftime(\'%H:%M\')', 'sprintf(\'%\' . (\'$1\' ? \'\' : \'02\') . \'d\', $this->_sec)', "\t", '$this->strftime(\'%H:%M:%S\')', '$this->strftime(Horde_Nls::getLangInfo(D_FMT))', '$this->strftime(Horde_Nls::getLangInfo(T_FMT))', 'substr(sprintf(\'%04d\', $this->_year), -2)', (int)$this->_year, '%'), $format); } Note, while I agree for this feature, must application / framework will have to be fixed, but also kept compatible with 5.3, 5.4, 5.5. Remi.