summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--ext/standard/basic_functions.c1
-rw-r--r--ext/standard/php_string.h1
-rw-r--r--ext/standard/string.c29
4 files changed, 32 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 74f647fcfd..fb3bdeb15f 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,7 @@ PHP NEWS
. array_diff_uassoc(). (Andrey)
. convert_uuencode(). (Ilia)
. convert_uudecode(). (Ilia)
+ . substr_compare(). (Ilia)
. pcntl_wait(). (GeorgeS)
- Added "resume_pos" context option to "ftp://" wrapper. (Sara)
- Added optional parameter to OCIWriteTemporaryLob() to specify the type of LOB
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 14c51179a9..60f01bf7d9 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -374,6 +374,7 @@ function_entry basic_functions[] = {
PHP_FE(str_word_count, NULL)
PHP_FE(str_split, NULL)
PHP_FE(strpbrk, NULL)
+ PHP_FE(substr_compare, NULL)
#ifdef HAVE_STRCOLL
PHP_FE(strcoll, NULL)
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h
index be64af0d6c..dac757b050 100644
--- a/ext/standard/php_string.h
+++ b/ext/standard/php_string.h
@@ -89,6 +89,7 @@ PHP_FUNCTION(str_shuffle);
PHP_FUNCTION(str_word_count);
PHP_FUNCTION(str_split);
PHP_FUNCTION(strpbrk);
+PHP_FUNCTION(substr_compare);
#ifdef HAVE_STRCOLL
PHP_FUNCTION(strcoll);
#endif
diff --git a/ext/standard/string.c b/ext/standard/string.c
index fe7553f13c..73775ad244 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -4662,6 +4662,35 @@ PHP_FUNCTION(strpbrk)
}
/* }}} */
+/* {{{ proto int substr_compare(string main_str, string str, int offset [, int length [, bool case_sensitivity]])
+ Binary safe optionally case insensitive comparison of 2 strings from an offset, up to length characters */
+PHP_FUNCTION(substr_compare)
+{
+ char *s1, *s2;
+ int s1_len, s2_len;
+ long offset, len=0;
+ zend_bool cs=0;
+ uint cmp_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if (len && offset >= s1_len) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The start position cannot exceed initial string length.");
+ RETURN_FALSE;
+ }
+
+ cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
+
+ if (!cs) {
+ RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
+ } else {
+ RETURN_LONG(zend_binary_strncasecmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
+ }
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4