Re: [PHP4BETA] New function chrcount (diff attached)

From: Date: Tue, 25 Apr 2000 06:59:48 +0000
Subject: Re: [PHP4BETA] New function chrcount (diff attached)
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-14038@lists.php.net to get a copy of this message
On Mon, Apr 24, 2000 at 01:59:55PM -0400, Peter Kovacs wrote: > I've created a new function chrcount (count_chars was already taken, and > count_char is too similar) which finds the number of times a character > appears in a string. count_chars does what you need. read the docs (not online yet) phpdoc/en/functions/strings.xml > > Let me know what you all think. > > Peter > > -------------------------------------------------- > Peter D. Kovacs KnowPost.com LLC > Lead Engineer peter@knowpost.com > -------------------------------------------------- > Index: basic_functions.c > =================================================================== > RCS file: /repository/php4/ext/standard/basic_functions.c,v > retrieving revision 1.185 > diff -u -r1.185 basic_functions.c > --- basic_functions.c 2000/04/19 18:36:50 1.185 > +++ basic_functions.c 2000/04/24 17:54:29 > @@ -122,6 +122,7 @@ > > PHP_FE(strnatcmp, NULL) > PHP_FE(strnatcasecmp, NULL) > + PHP_FE(chrcount, NULL) > PHP_FE(strspn, NULL) > PHP_FE(strcspn, NULL) > PHP_FE(strtok, NULL) > Index: php_string.h > =================================================================== > RCS file: /repository/php4/ext/standard/php_string.h,v > retrieving revision 1.11 > diff -u -r1.11 php_string.h > --- php_string.h 2000/04/12 19:39:02 1.11 > +++ php_string.h 2000/04/24 17:54:29 > @@ -84,6 +84,7 @@ > PHP_FUNCTION(substr_replace); > PHP_FUNCTION(strnatcmp); > PHP_FUNCTION(strnatcasecmp); > +PHP_FUNCTION(chrcount); > > #define strnatcmp(a, b) \ > strnatcmp_ex(a, strlen(a), b, strlen(b), 0) > Index: string.c > =================================================================== > RCS file: /repository/php4/ext/standard/string.c,v > retrieving revision 1.106 > diff -u -r1.106 string.c > --- string.c 2000/04/12 19:39:02 1.106 > +++ string.c 2000/04/24 17:54:29 > @@ -2472,6 +2478,28 @@ > (*s2)->value.str.val, (*s2)->value.str.len, > fold_case)); > } > + > +/* {{{ proto int chrcount(string str, string character) > + Find the number of times character occurs in str. */ > +PHP_FUNCTION(chrcount) > +{ > + zval **input, **chr; > + int i, length, count = 0; > + if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &input, &chr) == FAILURE) { > + WRONG_PARAM_COUNT; > + } > + > + convert_to_string_ex(input); > + convert_to_string_ex(chr); > + > + for (i = 0, length = (*input)->value.str.len; i < length; i++) { > + if ((*input)->value.str.val[i] == (*chr)->value.str.val[0]) { > + count++; > + } > + } > + RETURN_LONG(count); > +} > +/* }}} */ > > PHP_FUNCTION(strnatcmp) > { > -- > PHP 4.0 Beta Mailing List <http://www.php.net/version4/> > To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net > For additional commands, e-mail: php4beta-help@lists.php.net > To contact the list administrators, e-mail: php4beta-admin@lists.php.net -- Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!" Digital Collections Phone +49 40 235350 Fax +49 40 23535180 Hammerbrookstr. 93 20097 Hamburg / Germany

« previous php.version4 (#14038) next »