|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-08-16 20:57 UTC] liit at geeksbynature dot dk
Description:
------------
The function ereg() either returns (boolean)FALSE or (int)1, and not (boolean)FALSE or (boolean)TRUE
Reproduce code:
---------------
echo gettype(ereg("foo","foo"));
echo gettype(ereg("foo","bar"));
Expected result:
----------------
boolean
boolean
Actual result:
--------------
integer
boolean
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 14:00:01 2025 UTC |
ereg() still only returns int(1) or (boolean)FALSE. I've expanded my test-script a bit: <?php $a = ereg("fo","fo"); // Simple test to see if documentation is right (it's not) $b = ereg("bar","foobarbar"); // Is it the position of the first result, that is returned ? (no) $c = ereg("foo","bar"); // A negative test (works) echo $a . ":" . gettype($a). "\n"; echo $b . ":" . gettype($b). "\n"; echo $c . ":" . gettype($c). "\n"; ?> Result: 1:integer 1:integer :boolean According to the docs, it should be: 2:integer 3:integer :booleanIf I understand, this function should return the legth of the match. But it seems it has a bug, because it always return 1 if you don't pass the 3rd parameter. Or is it a feature that should be documented? <? echo ereg('foo', 'foo foo foo'); //1 echo ereg('foo', 'foo foo foo', $var); //3 echo ereg('foobar', 'foobar foo foo', $var2); //6 ?> Nuno