|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-16 05:35 UTC] skissane at iips dot mq dot edu dot au
[2004-08-16 05:36 UTC] skissane at iips dot mq dot edu dot au
[2004-12-06 16:00 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 16:00:01 2025 UTC |
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