The str_word_count () function calculates the number of words in a string. syntax: the str_word_count (string, return, char) parameter description is required for the string to be checked. retur... the str_word_count () function calculates the number of words in a string.
Syntax:Str_word_count (string, return, char)
Parameter description
String is required, which specifies the string to be checked.
Return (optional) specifies the return value of the str_word_count () function.
Possible values: 0-default, returns the number of words found, 1-returns an array containing the words in the string, 2-returns an array, the key is the position of the word in the string, and the value is the actual word.
Return (optional) specifies the special character recognized as a word. the parameter is added in php 5.1 and the code is as follows:
$ Str = "hello world"; // define the string $ result = str_word_count ($ str); // search for the number of words echo $ result; // output result echo"
"; $ Result = str_word_count ($ str, 1); // returns the array print_r ($ result); // outputs the result array.
Article URL:
Reprint ^ at will, but please attach the tutorial address.