php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43772 the pcre (preg_*) functions should be able to pre-compile regexps
Submitted: 2008-01-06 19:41 UTC Modified: 2008-01-06 20:07 UTC
From: php at linuxhosted dot net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.5 OS: n/a
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at linuxhosted dot net
New email:
PHP Version: OS:

 

 [2008-01-06 19:41 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-06 20:07 UTC] johannes@php.net
The compiled regexp is cached after the first use, no need to compile it manually.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC