php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #9309 update ereg function to return booleans instead of 0/1
Submitted: 2001-02-16 18:35 UTC Modified: 2002-04-27 14:49 UTC
From: krssak at upc dot uniba dot sk Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.3pl1 OS: debian linux
Private report: No CVE-ID: None
 [2001-02-16 18:35 UTC] krssak at upc dot uniba dot sk
$id_size=strlen($id_usr);
if (!ereg("([0-9]{$id_size})",$id_usr)){
  echo "Error ID";
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-16 23:19 UTC] andre@php.net
a) in fact is does return 1 and 0, that isn't exactly true
and false in php 4 anymore, either documentation or regex
code needs a small update... moving to change request

b) your problem is another, your regex is wrong, try echoing
your pattern before passing it to ereg() and you will see
that php ate up your brackets (eg. [0-9]2)

it should read like this:

if (!ereg('([0-9]{'.$id_size.'})',"$id_usr")){
  echo "Error ID";
}
 [2002-04-27 14:49 UTC] jimw@php.net
ereg() does return false when no matches are made, or the length of the match.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC