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
}
/* }}} */
-/* {{{ 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)
{
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);
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;
}
}
/* }}} */
-/* {{{ 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)
{
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);
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;
}