#43772 [Opn->Bgs]: the pcre (preg_*) functions should be able to pre-compile regexps

From: Date: Sun, 06 Jan 2008 20:08:00 +0000
Subject: #43772 [Opn->Bgs]: the pcre (preg_*) functions should be able to pre-compile regexps
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121085@lists.php.net to get a copy of this message
ID: 43772 Updated by: johannes@php.net Reported By: php at linuxhosted dot net -Status: Open +Status: Bogus Bug Type: Feature/Change Request Operating System: n/a PHP Version: 5.2.5 New Comment: The compiled regexp is cached after the first use, no need to compile it manually. Previous Comments: ------------------------------------------------------------------------ [2008-01-06 19:41:16] php at linuxhosted dot net Description: ------------ what I'm proposing is, adding a function (perhaps named preg_compile) that would accept 1 string parameter $pattern. the function would return a resource with the compiled pcre code which could be used anywhere in the other preg_* functions where a string for the pattern would be accepted. this way if you need to do 1000s of pcre matches of the same pattern(s) on different data, it would not require internally doing pcre_compile() over and over, saving very valuable cpu time. Reproduce code: --------------- <?php $pattern = preg_compile("/s[i1]mpl[e3] pattern here/i"); // returns a new type of resource if (preg_match($pattern, "simple pattern here")) // which can then be used anywhere the normal string pattern could be echo "pattern matches\n"; ?> Expected result: ---------------- well, obviously if this feature was added i'd expect to see: pattern matches Actual result: -------------- since this is not actually implemented i'd just get a fatal error :P ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43772&edit=1

« previous php.bugs (#121085) next »