Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create str_contains PHP function #5179

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */
PHP_FE(strtok, arginfo_strtok)
PHP_FE(strtoupper, arginfo_strtoupper)
PHP_FE(strtolower, arginfo_strtolower)
PHP_FE(str_contains, arginfo_str_contains)
PHP_FE(strpos, arginfo_strpos)
PHP_FE(stripos, arginfo_stripos)
PHP_FE(strrpos, arginfo_strrpos)
Expand Down
2 changes: 2 additions & 0 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ function stristr(string $haystack, string $needle, bool $before_needle = false):

function strstr(string $haystack, string $needle, bool $before_needle = false): string|false {}

function str_contains(string $haystack, string $needle): bool {}

function strpos(string $haystack, string $needle, int $offset = 0): int|false {}

function stripos(string $haystack, string $needle, int $offset = 0): int|false {}
Expand Down
5 changes: 5 additions & 0 deletions ext/standard/basic_functions_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,11 @@ ZEND_END_ARG_INFO()

#define arginfo_strstr arginfo_stristr

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_str_contains, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
ZEND_END_ARG_INFO()
nikic marked this conversation as resolved.
Show resolved Hide resolved

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strpos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/php_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ PHP_FUNCTION(basename);
PHP_FUNCTION(dirname);
PHP_FUNCTION(pathinfo);
PHP_FUNCTION(strstr);
PHP_FUNCTION(str_contains);
PHP_FUNCTION(strpos);
PHP_FUNCTION(stripos);
PHP_FUNCTION(strrpos);
Expand Down
15 changes: 15 additions & 0 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,21 @@ PHP_FUNCTION(strstr)
}
/* }}} */

/* {{{ proto bool str_contains(string haystack, string needle)
Checks if a string contains another */
PHP_FUNCTION(str_contains)
{
zend_string *haystack, *needle;

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR(haystack)
Z_PARAM_STR(needle)
ZEND_PARSE_PARAMETERS_END();

RETURN_BOOL(php_memnstr(ZSTR_VAL(haystack), ZSTR_VAL(needle), ZSTR_LEN(needle), ZSTR_VAL(haystack) + ZSTR_LEN(haystack)));
}
/* }}} */

/* {{{ proto string strchr(string haystack, string needle)
An alias for strstr */
/* }}} */
Expand Down