php str_word_count() function


  Translation results:

string

英[strɪŋ] 美[strɪŋ]

n.String; rope, belt; thread, plant fiber; [Computer Science] string

vt. Wind, tune; line up in a row or series; tie, tie or hang with a thread; extend or expand

word

英[wɜ:d] US [wɜ:rd]

n. Word; Discourse; Promise; Message

vt. Wording, wording; Expression in words

vi. Speech

count

UK[kaʊnt] US[kaʊnt]

n.Total number; Count; Count; Argument

v. Count; Calculate the total; Count... important

php str_word_count() functionsyntax

Function:Calculate the number of words in a string

Syntax: str_word_count(string,return,char)

Parameters:

ParametersDescription
stringRequired . Specifies the string to check.
returnOptional. 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 where the keys are the word positions in the string and the keys are the actual words.
charOptional. Specifies the special characters that are treated as words.

#Description: Count the number of words in the string.

php str_word_count() functionexample

<?php
echo str_word_count("I love php!");
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

3
<?php
echo str_word_count("i study php at php.cn");
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

6

Home

Videos

Q&A