php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #29039 ereg {0,255} limited to 255 ... and not documented
Submitted: 2004-07-06 23:41 UTC Modified: 2004-07-12 10:09 UTC
Votes:5
Avg. Score:3.8 ± 1.5
Reproduced:3 of 4 (75.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: info at smithfieldentertainment dot com Assigned:
Status: Wont fix Package: Documentation problem
PHP Version: Irrelevant OS: UNIX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
31 + 41 = ?
Subscribe to this entry?

 
 [2004-07-06 23:41 UTC] info at smithfieldentertainment dot com
Description:
------------
I sent the following email to Mehdi Achour <didou@keliglia.com>

---------------
Hi,

 

I discovered (the hard way after hours of code troubleshooting) that ereg/eregi/etc. functions have a very useful but LIMITED length function.

It seems that while the ereg functions will search for matches in (any?) length code, the length limiter {0, 255} is limited to 255.

 

I was trying to match lengths of 350 and 800? but couldn?t figure out why I was getting an error.  There?s no documentation on this anywhere that I could find.

 

Please add it to all applicable regular expression match items that it applies to.

 

Thanks!

-- CJ Greiner

info@SmithfieldEntertainment.com

http://www.SmithfieldEntertainment.com

757-356-1166

 

 


Reproduce code:
---------------
if (eregi("^([a-z0-9 $&*?\'.-]{100,300})$", $register_data[register_summary], $ereg_results) == FALSE) {
  $error_message .= '<br>Subject Summary:  Please use only letters, numbers, and punctuation: \'-$&amp;*?<br>';
}

Expected result:
----------------
if the user input $register_data[register_summary] does not match the regular expression OR is ouside the acceptable length range of 100-300 letters, then the expression should return FALSE and assign an $error_message.

Actual result:
--------------
Even when the user input for $register_data[register_summary] had acceptable characters AND had acceptable lengths...

The code failed because the max length of 300 {100, 300} was causing a FALSE or FAIL.

I experimented with the length until I brought it down to 255... then it worked.

This limit is not documented anywhere.
There should be no limit... or at least a much higher limit, since the matching expression will work on a much longer string if no length limit is placed in it.

Thanks!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-08 13:19 UTC] nlopess@php.net
We have discussed this and we decided not to document this behaviour, has this is cleary explained in the man page.
 [2004-07-11 08:32 UTC] info at smithfieldentertainment dot com
It seems the only useful information about regular expressions in PHP can be found at:

http://us4.php.net/pcre.pattern.syntax
PCRE Pattern Syntax.

It DOES discuss the 
{ - start min/max quantifier, and the
} - end min/max quantifier

... but does not mention any limits on PHP's ability to process strings greater than 255 in length.

-------------------
The PHP manual could use additional helpful info on regular expressions.  It would also be helpful if the information you've already included was more complete.
Limits like {0, 255} ARE important to programmers.
I was able to work around it... but it took a few hours to find the limitation in the first place, and several lines of code to work around it once I knew what the problem was. 

Please either fix PHP, or fix its documentation.

Thank you.
 [2004-07-12 10:09 UTC] vrana@php.net
PCRE Pattern Syntax is documentation to Perl Compatible Regular Expressions, not to POSIX Regular Expressions. There's no such limitation in PCRE.

In Introduction part of http://www.php.net/manual/en/ref.regex.php is link to regular expression documentation - man page regex.7 where is written: "A bound is `{' followed by an unsigned decimal integer, possibly followed by `,' possibly followed by another unsigned decimal integer, always followed by `}'. The integers must lie between 0 and RE_DUP_MAX (255(!)) inclusive".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC