From: Felipe Pena Date: Fri, 1 Feb 2008 12:28:44 +0000 (+0000) Subject: MFH: New parameter 'before_needle' X-Git-Tag: RELEASE_1_3_1~193 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79cfa91a435f90b976006e5bcaae4f7b4e774df2;p=php MFH: New parameter 'before_needle' --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 46c073d7a4..13e822942c 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2536,15 +2536,17 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_pathinfo, 0, 0, 1) ZEND_END_ARG_INFO() static -ZEND_BEGIN_ARG_INFO(arginfo_stristr, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_stristr, 0, 0, 2) ZEND_ARG_INFO(0, haystack) ZEND_ARG_INFO(0, needle) + ZEND_ARG_INFO(0, part) ZEND_END_ARG_INFO() static -ZEND_BEGIN_ARG_INFO(arginfo_strstr, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_strstr, 0, 0, 2) ZEND_ARG_INFO(0, haystack) ZEND_ARG_INFO(0, needle) + ZEND_ARG_INFO(0, part) ZEND_END_ARG_INFO() static diff --git a/ext/standard/string.c b/ext/standard/string.c index 41844a54e6..5d5b963caf 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1687,7 +1687,7 @@ PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end) } /* }}} */ -/* {{{ proto string stristr(string haystack, string needle) +/* {{{ proto string stristr(string haystack, string needle[, bool part]) Finds first occurrence of a string within another, case insensitive */ PHP_FUNCTION(stristr) { @@ -1696,9 +1696,10 @@ PHP_FUNCTION(stristr) int found_offset; char *haystack_orig; char needle_char[2]; + zend_bool part = 0; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZ|b", &haystack, &needle, &part) == FAILURE) { + return; } SEPARATE_ZVAL(haystack); @@ -1732,7 +1733,11 @@ PHP_FUNCTION(stristr) if (found) { found_offset = found - Z_STRVAL_PP(haystack); - RETVAL_STRINGL(haystack_orig + found_offset, Z_STRLEN_PP(haystack) - found_offset, 1); + if (part) { + RETVAL_STRINGL(haystack_orig, found_offset, 1); + } else { + RETVAL_STRINGL(haystack_orig + found_offset, Z_STRLEN_PP(haystack) - found_offset, 1); + } } else { RETVAL_FALSE; } @@ -1741,7 +1746,7 @@ PHP_FUNCTION(stristr) } /* }}} */ -/* {{{ proto string strstr(string haystack, string needle) +/* {{{ proto string strstr(string haystack, string needle[, bool part]) Finds first occurrence of a string within another */ PHP_FUNCTION(strstr) { @@ -1749,9 +1754,10 @@ PHP_FUNCTION(strstr) char *found = NULL; char needle_char[2]; long found_offset; + zend_bool part = 0; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZ|b", &haystack, &needle, &part) == FAILURE) { + return; } convert_to_string_ex(haystack); @@ -1779,7 +1785,11 @@ PHP_FUNCTION(strstr) if (found) { found_offset = found - Z_STRVAL_PP(haystack); - RETURN_STRINGL(found, Z_STRLEN_PP(haystack) - found_offset, 1); + if (part) { + RETURN_STRINGL(Z_STRVAL_PP(haystack), found_offset, 1); + } else { + RETURN_STRINGL(found, Z_STRLEN_PP(haystack) - found_offset, 1); + } } else { RETURN_FALSE; }