]> granicus.if.org Git - php/commitdiff
Added strpbrk(), which is essentially a wrapper around C's strpbrk function
authorIlia Alshanetsky <iliaa@php.net>
Tue, 11 Feb 2003 22:47:26 +0000 (22:47 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 11 Feb 2003 22:47:26 +0000 (22:47 +0000)
that allows searching through a string for a character list.

ext/standard/basic_functions.c
ext/standard/php_string.h
ext/standard/string.c

index 5c2f1880a457bfc88aa61e0aadd8427bcd4304dc..d82913aed08604cc39a93fc58004d88886dd5bf2 100644 (file)
@@ -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)
index 60a6c23af2bf93a69a9d0804629af8e5579c14c4..18e53afe2798acc38d7003190a2baf5bca22e770 100644 (file)
@@ -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
index a86072a03ed960b0be1f58c289a919914ed99cff..bbdb38abe8b684174ee7b6b06987d66d1f03da08 100644 (file)
@@ -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: