The two attached files add a sixth mode to count chars, one that comes up now and again.
This is the same as mode 1, but the resulting array has the actual char as the array index instead of the byte-value. This can be used in place of preg_split('//', $string) and such. I've also prepared patches for the documentation and for 4.3.2 to go along with this. You can also find the patches online: http://www.joeysmith.com/CVS_HEAD.patch http://www.joeysmith.com/PHP_4_3_2.patch http://www.joeysmith.com/phpdoc.patch
? CVS_HEAD.patch Index: ext/standard/string.c =================================================================== RCS file: /repository/php4/ext/standard/string.c,v retrieving revision 1.390 diff -u -r1.390 string.c --- ext/standard/string.c 11 Jun 2003 02:16:19 -0000 1.390 +++ ext/standard/string.c 14 Jun 2003 21:44:19 -0000 @@ -4053,6 +4053,7 @@ int len, inx; char retstr[256]; int retlen=0; + char temp[2]; if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &input, &mode) == FAILURE) { WRONG_PARAM_COUNT; @@ -4064,7 +4065,7 @@ convert_to_long_ex(mode); mymode = Z_LVAL_PP(mode); - if (mymode < 0 || mymode > 4) { + if (mymode < 0 || mymode > 5) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown mode."); RETURN_FALSE; } @@ -4080,7 +4081,7 @@ len--; } - if (mymode < 3) { + if ((mymode < 3) || (mymode == 5)) { array_init(return_value); } @@ -4107,6 +4108,13 @@ case 4: if (chars[inx] == 0) { retstr[retlen++] = inx; + } + break; + case 5: + if (chars[inx] > 0) { + temp[0] = inx; + temp[1] = 0; + add_assoc_long_ex(return_value, temp, sizeof(temp), chars[inx]); } break; }
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php