Skip to content

Commit

Permalink
Create str_contains php function
Browse files Browse the repository at this point in the history
  • Loading branch information
philippta committed Feb 14, 2020
1 parent a957e84 commit 0de0e3d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
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
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

0 comments on commit 0de0e3d

Please sign in to comment.