From: x-g at monkeyblah dot com Operating system: Windows XP PHP version: 4.3.8 PHP Bug Type: *Regular Expressions Bug description: preg_match offset not equivalent to substr
Description: ------------ According to the manual, passing an offset to preg_match is equivalent to passing substr($string, $offset) to the function. This is not the case, however; regular expressions that match on beginning-of-string will not match if an offset is specified, but work fine if substr() is used in a supposedly equivalent manner. Either this is a problem with regular expressions giving unexpected behaviour, or perhaps the manual just need to be changed to reflect the difference. Reproduce code: --------------- $string = "abc def"; if (preg_match("/^[a-zA-Z]+/", $string, $matches, 0, 4)) echo "Matches\n"; else echo "Does not match\n"; if (preg_match("/^[a-zA-Z]+/", substr($string, 4), $matches, 0)) echo "Matches\n"; else echo "Does not match\n"; Expected result: ---------------- Matches Matches Actual result: -------------- Does not match Matches -- Edit bug report at http://bugs.php.net/?id=29427&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29427&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29427&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=29427&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=29427&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=29427&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=29427&r=needscript Try newer version: http://bugs.php.net/fix.php?id=29427&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=29427&r=support Expected behavior: http://bugs.php.net/fix.php?id=29427&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=29427&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=29427&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=29427&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29427&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=29427&r=dst IIS Stability: http://bugs.php.net/fix.php?id=29427&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=29427&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=29427&r=float