From: Ilia Alshanetsky Date: Tue, 11 Feb 2003 22:47:26 +0000 (+0000) Subject: Added strpbrk(), which is essentially a wrapper around C's strpbrk function X-Git-Tag: RELEASE_0_5~1096 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53f96c8b02690d2183e72a76a547cb8b08aacdf2;p=php Added strpbrk(), which is essentially a wrapper around C's strpbrk function that allows searching through a string for a character list. --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 5c2f1880a4..d82913aed0 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -343,6 +343,7 @@ function_entry basic_functions[] = { PHP_FE(str_shuffle, NULL) PHP_FE(str_word_count, NULL) PHP_FE(str_split, NULL) + PHP_FE(strpbrk, NULL) #ifdef HAVE_STRCOLL PHP_FE(strcoll, NULL) diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index 60a6c23af2..18e53afe27 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -88,6 +88,7 @@ PHP_FUNCTION(sscanf); PHP_FUNCTION(str_shuffle); PHP_FUNCTION(str_word_count); PHP_FUNCTION(str_split); +PHP_FUNCTION(strpbrk); #ifdef HAVE_STRCOLL PHP_FUNCTION(strcoll); #endif diff --git a/ext/standard/string.c b/ext/standard/string.c index a86072a03e..bbdb38abe8 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -4379,6 +4379,30 @@ PHP_FUNCTION(str_split) } /* }}} */ +/* {{{ proto array strpbrk(string haystack, string char_list) + Search a string for any of a set of characters */ +PHP_FUNCTION(strpbrk) +{ + char *haystack, *char_list; + int haystack_len, char_list_len; + char *p; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &haystack, &haystack_len, &char_list, &char_list_len) == FAILURE) { + RETURN_FALSE; + } + + if (!char_list_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The character list cannot be empty."); + RETURN_FALSE; + } + + if ((p = strpbrk(haystack, char_list))) { + RETURN_STRINGL(p, (haystack + haystack_len - p), 1); + } else { + RETURN_FALSE; + } +} +/* }}} */ /* * Local variables: