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)