Skip to content

Commit 0de0e3d

Browse files
committed
Create str_contains php function
1 parent a957e84 commit 0de0e3d

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-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.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ function stristr(string $haystack, string $needle, bool $before_needle = false):
553553

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

556+
function str_contains(string $haystack, string $needle): bool {}
557+
556558
function strpos(string $haystack, string $needle, int $offset = 0): int|false {}
557559

558560
function stripos(string $haystack, string $needle, int $offset = 0): int|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)