]> granicus.if.org Git - php/commitdiff
Allow substr_compare() to take a negative offset to facilitate start of the
authorIlia Alshanetsky <iliaa@php.net>
Mon, 26 Sep 2005 23:08:10 +0000 (23:08 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 26 Sep 2005 23:08:10 +0000 (23:08 +0000)
comparison from the end of string.

ext/standard/string.c

index 4f255d4d8e9634d73d80c4e98332474f55526097..09d68c112377d843956e01bc9b1c4cb4c814e57d 100644 (file)
@@ -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;