Skip to content

Commit 163c576

Browse files
committed
Create str_contains php function
1 parent a957e84 commit 163c576

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

ext/standard/basic_functions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */
173173
PHP_FE(strtok, arginfo_strtok)
174174
PHP_FE(strtoupper, arginfo_strtoupper)
175175
PHP_FE(strtolower, arginfo_strtolower)
176+
PHP_FE(str_contains, arginfo_str_contains)
176177
PHP_FE(strpos, arginfo_strpos)
177178
PHP_FE(stripos, arginfo_stripos)
178179
PHP_FE(strrpos, arginfo_strrpos)

ext/standard/basic_functions_arginfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_stristr, 0, 2, MAY_BE_STRING|MAY
875875
ZEND_ARG_TYPE_INFO(0, before_needle, _IS_BOOL, 0)
876876
ZEND_END_ARG_INFO()
877877

878+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_str_contains, 0, 1, _IS_BOOL)
879+
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
880+
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
881+
ZEND_END_ARG_INFO()
882+
878883
#define arginfo_strstr arginfo_stristr
879884

880885
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strpos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)

ext/standard/php_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ PHP_FUNCTION(basename);
3939
PHP_FUNCTION(dirname);
4040
PHP_FUNCTION(pathinfo);
4141
PHP_FUNCTION(strstr);
42+
PHP_FUNCTION(str_contains);
4243
PHP_FUNCTION(strpos);
4344
PHP_FUNCTION(stripos);
4445
PHP_FUNCTION(strrpos);

ext/standard/string.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,21 @@ PHP_FUNCTION(strstr)
18511851
}
18521852
/* }}} */
18531853

1854+
/* {{{ proto bool str_contains(string haystack, string needle)
1855+
Checks if a string contains another */
1856+
PHP_FUNCTION(str_contains)
1857+
{
1858+
zend_string *haystack, *needle;
1859+
1860+
ZEND_PARSE_PARAMETERS_START(2, 2)
1861+
Z_PARAM_STR(haystack)
1862+
Z_PARAM_STR(needle)
1863+
ZEND_PARSE_PARAMETERS_END();
1864+
1865+
RETURN_BOOL(php_memnstr(ZSTR_VAL(haystack), ZSTR_VAL(needle), ZSTR_LEN(needle), ZSTR_VAL(haystack) + ZSTR_LEN(haystack)));
1866+
}
1867+
/* }}} */
1868+
18541869
/* {{{ proto string strchr(string haystack, string needle)
18551870
An alias for strstr */
18561871
/* }}} */

0 commit comments

Comments
 (0)