php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47278 preg_match behaves different to version 4.4.4
Submitted: 2009-02-02 13:44 UTC Modified: 2009-02-02 23:31 UTC
From: franklyn dot santana at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.8 OS: Windows 2003 Server
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: franklyn dot santana at gmail dot com
New email:
PHP Version: OS:

 

 [2009-02-02 13:44 UTC] franklyn dot santana at gmail dot com
Description:
------------
I have a code for url rewrite, I use the preg_match function to separate the GET parameters.

The code works fine in PHP 4.4.4, I get a matches array with the GET parameters. But it doesn't work on PHP 5.28, the matches array is empty.

I was checking the documentation and It seems there are not changes on this function. 

Reproduce code:
---------------
$url="http://localhost/test+param-2009.html";

preg_match("/\/[^+]*\+?[^+]+\++([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?".
"([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?".
"([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)-?([^-]*)\.html/i", $url, $parameters);

 print_r($parameters)


Expected result:
----------------
/*tested on PHP 4.4.4
Array ( [0] => //localhost/test+param-2009.html [1] => param [2] => 2009 [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => [20] => ) 

Actual result:
--------------
Array ( ) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-02 20:30 UTC] franklyn dot santana at gmail dot com
I read somewhere (right now I don't remember where) there is problem with long regular expressions in php5. Is that true? I made the regular expression shorter, now the script works (with some limitations due to the short regex).
 [2009-02-02 20:46 UTC] felipe@php.net
Check preg_last_error().
http://docs.php.net/manual/en/function.preg-last-error.php
 [2009-02-02 23:23 UTC] jani@php.net
Hint: PREG_BACKTRACK_LIMIT_ERROR


 [2009-02-02 23:31 UTC] franklyn dot santana at gmail dot com
yes, I didn't know there was a PREG_BACKTRACK_LIMIT_ERROR option at php.ini in php5. I had to set it to 500000 for the script to work. Thanks people :D
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 05 02:01:35 2025 UTC