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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 13:01:33 2024 UTC