str_word_count
Return information about the words used in the string
str_word_count()
function calculates the number of words in a string.
Calculate the number of words in the string "I love Shanghai!":
<?php echo str_word_count ( "I love Shanghai!" ) ; ?>
Try it yourself
Returns an array containing words in a string:
<?php print_r ( str_word_count ( "I love Shanghai!" , 1 ) ) ; ?>
Try it yourself
Returns an array where the key name is the position of the word in the string and the key value is the actual word:
<?php print_r ( str_word_count ( "I love Shanghai!" , 2 ) ) ; ?>
Try it yourself
Set and not set char parameters:
<?php print_r ( str_word_count ( "I love Shanghai & good morning!" , 1 ) ) ; print_r ( str_word_count ( "I love Shanghai & good morning!" , 1 , "&" ) ) ; ?>
Try it yourself
str_word_count ( string , return , char )
parameter | describe |
---|---|
string | Required. Specifies the string to be checked. |
Return |
Optional. Specifies the return value of the str_word_count() function. Possible values:
|
char | Optional. Specifies special characters that are considered words. |