php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #862 problem in eregi()
Submitted: 1998-10-20 17:17 UTC Modified: 1998-10-29 22:04 UTC
From: markjr at easyDNS dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.5 OS: linux 2.0.35
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: markjr at easyDNS dot com
New email:
PHP Version: OS:

 

 [1998-10-20 17:17 UTC] markjr at easyDNS dot com
eregi("[^a-z0-9\.\-]", "test-ing") returns false
eregi("[^a-z0-9\-\.]", "test-ing") returns true

Switching the escaped "." and "-" causes the
pattern to fail erroneously. The behaviour goes
away if you use an inclusive regex (read:
lose the "^")

here's a short script to test with 

<?
function isValidAddr ($addr) {
        if(eregi("[^a-z0-9\-\.]",$addr)):
                return(false);
        else:
                return(true);
        endif;
        };

echo isValidAddr("Tesdt-jkjk") ? "true" : "false";
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-10-29 22:04 UTC] rasmus
You have a number of problems in your regular expressions there.  First, there is no such thing as \- and even if there was you would have to write it as \\- because inside a double-quoted string in PHP escape chars are parsed.  In order to get the eregi() function to see \- you would have to escape the \ and thus have \\-.  That isn't you problem though.  I quote from the Extended Regular Expression docs (see regex/regex.7 in the PHP distribution):
To  include  a  literal `]' in the list, make it the first
character (following a possible `^').  To include  a  lit-
eral `-', make it the first or last character, or the sec-
ond endpoint of a range.  To use  a  literal  `-'  as  the
first  endpoint of a range, enclose it in `[.' and `.]' to
make it a collating element (see below).  With the  excep-
tion  of  these  and some combinations using `[' (see next
paragraphs), all other special characters, including  `\',
lose  their  special significance within a bracket expres-
sion.
So, this tells you that you cannot put a '-' in the middle of a range like that.  I do not think this is a bug in PHP.  PHP's behaviour is entirely consistent with that definition.
 [2023-03-06 07:15 UTC] asghhs at gmail dot com
MYHR KOHLS is an online portal that enables Kohl's employees to access their HR information and manage their benefits. This portal provides employees with a convenient way to view and manage their payroll, vacation time, health benefits, and other HR related information. It also allows them to access a variety of tools such as tax forms, pension plans, and more. MYHR KOHLS is a great tool for employers as it helps them keep track of employee information in one place. It also simplifies the process of managing employee benefits and payrolls.
(https://myhrwork.com/kohls/myhr-kohls-login/)github.com
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Jun 10 22:00:01 2026 UTC