From 200d5924cf844b43ffe089ced760452e6a89bc71 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 26 Sep 2005 23:08:10 +0000 Subject: [PATCH] Allow substr_compare() to take a negative offset to facilitate start of the comparison from the end of string. --- ext/standard/string.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/standard/string.c b/ext/standard/string.c index 4f255d4d8e..09d68c1123 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -5770,6 +5770,10 @@ PHP_FUNCTION(substr_compare) RETURN_FALSE; } + if (offset < 0) { /* negative offset, start comparison at the end of string */ + offset = s1_len + offset; + } + if (len && offset >= s1_len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The start position cannot exceed initial string length."); RETURN_FALSE; -- 2.40.0