Definition and usage
This str_word_count () function counts a string.
Syntax
Str_word_count (string, return, char)
| Parameter | Description |
|---|
| String | Required. Specified string check |
| Return | Optional. Str_word_count () function of the returned value. Possible value: 0-default. Returns word count discovery 1-returns an array from string 2-returns an array in the key position is that the word string, and the value is the actual word |
| Char | Optional. Special characters are considered as words. Note: this parameter is used in PHP 5.1. |
Let's look at the instance.
<? Phpecho str_word_count ("Hello world! ");?>The output is 2.
Let's look at it again.
<? Phpprint_r (str_word_count ("Hello world! ", 1);?>
Result.
Array ([0] => Hello [1] => world) |
Check again.
<? Phpprint_r (str_word_count ("Hello world! ", 2);?>
Output result
Array ([0] => Hello [6] => world)
Example 4
Str_word_count () does not match the Coke parameter:
<? Phpprint_r (str_word_count ("Hello world & good morning! ", 1); print_r (str_word_count (" Hello world & good morning! ", 1," & ");?>
Output.
Array ([0] => Hello [1] => world [2] => good [3] => morning)
Array ([0] => Hello [1] => world [2] => & [3] => good [4] => morning)