*/
PHP_FUNCTION(str_word_count)
{
- zval **str, **o_format, **also_alphas;
- char *s, *e, *p, *buf;
- char *p_also = NULL;
- int word_count = 0;
- int type = 0;
- int n_args = ZEND_NUM_ARGS();
-
- if (n_args > 3 || n_args < 1 || zend_get_parameters_ex(n_args, &str, &o_format, &also_alphas) == FAILURE) {
+ char *buf, *str, *char_list = NULL, *p, *e, *s, ch[256];
+ int str_len, char_list_len, word_count = 0;
+ long type = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len, &type, &char_list, &char_list_len) == FAILURE) {
WRONG_PARAM_COUNT;
}
- switch (n_args) {
- case 3:
- convert_to_string_ex(also_alphas);
- if (Z_STRLEN_PP(also_alphas)) {
- p_also = Z_STRVAL_PP(also_alphas);
- }
- case 2:
- convert_to_long_ex(o_format);
- type = Z_LVAL_PP(o_format);
+
+ if (char_list) {
+ php_charmask(char_list, char_list_len, ch TSRMLS_CC);
+ }
+
+ p = str;
+ e = str + str_len;
- if (type != 1 && type !=2 && !(n_args >= 3 && type == 0)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "The specified format parameter, '%d' is invalid.", type);
- RETURN_FALSE;
- }
- if (type) {
- array_init(return_value);
- }
+ if (type == 1 || type == 2) {
+ array_init(return_value);
}
-
- convert_to_string_ex(str);
- e = Z_STRLEN_PP(str) + (p = s = Z_STRVAL_PP(str));
+
while (p < e) {
if (isalpha(*p++)) {
- s = p - 1; /* the word starts at s */
- while (isalpha(*p) || *p == '\'' || (*p == '-' && isalpha(*(p+1)))
- || (p_also && php_memnstr(p_also, p, 1, p_also + Z_STRLEN_PP(also_alphas)))
- )
- {
+ s = p - 1;
+ while (isalpha(*p) || *p == '\'' || (*p == '-' && isalpha(*(p+1))) || (char_list && ch[(unsigned char)*p])) {
p++;
}
break;
case 2:
buf = estrndup(s, (p-s));
- add_index_stringl(return_value, (s - Z_STRVAL_PP(str)), buf, p-s, 1);
+ add_index_stringl(return_value, (s - str), buf, p-s, 1);
efree(buf);
break;
default:
string(5) "today"
}
int(6)
+NULL
+NULL
+NULL
+NULL
-Warning: str_word_count(): The specified format parameter, '3' is invalid. in %s on line 9
-bool(false)
+Warning: str_word_count() expects parameter 2 to be long, array given in %s on line 13
-Warning: str_word_count(): The specified format parameter, '123' is invalid. in %s on line 10
-bool(false)
+Warning: Wrong parameter count for str_word_count() in %s on line 13
+NULL
-Warning: str_word_count(): The specified format parameter, '-1' is invalid. in %s on line 11
-bool(false)
+Warning: str_word_count() expects parameter 2 to be long, string given in %s on line 14
-Warning: str_word_count(): The specified format parameter, '1569325056' is invalid. in %s on line 12
-bool(false)
-
-Warning: str_word_count(): The specified format parameter, '0' is invalid. in %s on line 13
-bool(false)
-
-Warning: str_word_count(): The specified format parameter, '0' is invalid. in %s on line 14
-bool(false)
+Warning: Wrong parameter count for str_word_count() in %s on line 14
+NULL
string(55) "Hello friend, you're
looking good today!"
int(5)
int(6)
int(5)
-Notice: Array to string conversion in %s on line 21
-int(7)
+Warning: str_word_count() expects parameter 3 to be string, array given in %s on line 21
-Notice: Object of class stdClass to string conversion in %s on line 22
-int(7)
+Warning: Wrong parameter count for str_word_count() in %s on line 21
+NULL
+
+Warning: str_word_count() expects parameter 3 to be string, object given in %s on line 22
+
+Warning: Wrong parameter count for str_word_count() in %s on line 22
+NULL
int(7)
array(5) {
[0]=>
string(3) "foo"
}
-Notice: Array to string conversion in %s on line 27
-array(7) {
- [0]=>
- string(1) "F"
- [1]=>
- string(1) "o"
- [2]=>
- string(1) "B"
- [3]=>
- string(1) "r"
- [4]=>
- string(1) "s"
- [5]=>
- string(3) "bar"
- [6]=>
- string(3) "foo"
-}
+Warning: str_word_count() expects parameter 3 to be string, array given in %s on line 27
-Notice: Object of class stdClass to string conversion in %s on line 28
-array(7) {
- [0]=>
- string(1) "F"
- [1]=>
- string(1) "o"
- [2]=>
- string(1) "B"
- [3]=>
- string(1) "r"
- [4]=>
- string(1) "s"
- [5]=>
- string(3) "bar"
- [6]=>
- string(3) "foo"
-}
+Warning: Wrong parameter count for str_word_count() in %s on line 27
+NULL
+
+Warning: str_word_count() expects parameter 3 to be string, object given in %s on line 28
+
+Warning: Wrong parameter count for str_word_count() in %s on line 28
+NULL
array(7) {
[0]=>
string(1) "F"
string(3) "foo"
}
-Notice: Array to string conversion in %s on line 33
-array(7) {
- [0]=>
- string(1) "F"
- [2]=>
- string(1) "o"
- [4]=>
- string(1) "B"
- [6]=>
- string(1) "r"
- [9]=>
- string(1) "s"
- [11]=>
- string(3) "bar"
- [15]=>
- string(3) "foo"
-}
+Warning: str_word_count() expects parameter 3 to be string, array given in %s on line 33
-Notice: Object of class stdClass to string conversion in %s on line 34
-array(7) {
- [0]=>
- string(1) "F"
- [2]=>
- string(1) "o"
- [4]=>
- string(1) "B"
- [6]=>
- string(1) "r"
- [9]=>
- string(1) "s"
- [11]=>
- string(3) "bar"
- [15]=>
- string(3) "foo"
-}
+Warning: Wrong parameter count for str_word_count() in %s on line 33
+NULL
+
+Warning: str_word_count() expects parameter 3 to be string, object given in %s on line 34
+
+Warning: Wrong parameter count for str_word_count() in %s on line 34
+NULL
array(7) {
[0]=>
string(1) "F"