From c8896a38aea3b220406d9355851ff9c92d9da57c Mon Sep 17 00:00:00 2001 From: James Moore Date: Fri, 2 Nov 2001 19:19:24 +0000 Subject: [PATCH] @- Fix behaviour of strtok. Bug 13866 (jmoore) # I have brought the behaviour of strtok into line with how the # libc strtok's behave. currently given # string> # three recursive calls to strtok returns . , # it now returns , , . (there was some # debate in #php.bugs if it should return , , false, # but php's strtok now behaves the same way as the libc version. --- ext/standard/string.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 4c90637664..47f95d5c38 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -923,6 +923,7 @@ PHP_FUNCTION(strtok) char *token_end; char *p; char *pe; + int skipped = 0; if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) @@ -963,12 +964,15 @@ PHP_FUNCTION(strtok) /* Skip leading delimiters */ while (STRTOK_TABLE(p)) + { if (++p >= pe) { /* no other chars left */ BG(strtok_last) = NULL; RETVAL_FALSE; goto restore; } + skipped++; + } /* We know at this place that *p is no delimiter, so skip it */ while (++p < pe) @@ -977,7 +981,7 @@ PHP_FUNCTION(strtok) if (p - BG(strtok_last)) { return_token: - RETVAL_STRINGL(BG(strtok_last), p - BG(strtok_last), 1); + RETVAL_STRINGL(BG(strtok_last) + skipped, (p - BG(strtok_last)) - skipped, 1); BG(strtok_last) = p + 1; } else { RETVAL_FALSE; -- 2.40.0