str_word_count
返回有關字符串中使用的單詞的信息
str_word_count()
函數計算字符串中的單詞數。
計算字符串"I love Shanghai!" 中的單詞數:
<?php echo str_word_count ( "I love Shanghai!" ) ; ?>
親自試一試
返回包含字符串中的單詞的數組:
<?php print_r ( str_word_count ( "I love Shanghai!" , 1 ) ) ; ?>
親自試一試
返回一個數組,其中的鍵名是單詞在字符串中的位置,鍵值是實際的單詞:
<?php print_r ( str_word_count ( "I love Shanghai!" , 2 ) ) ; ?>
親自試一試
設置及不設置char 參數:
<?php print_r ( str_word_count ( "I love Shanghai & good morning!" , 1 ) ) ; print_r ( str_word_count ( "I love Shanghai & good morning!" , 1 , "&" ) ) ; ?>
親自試一試
str_word_count ( string , return , char )
參數 | 描述 |
---|---|
string | 必需。規定要檢查的字符串。 |
return |
可選。規定str_word_count() 函數的返回值。 可能的值:
|
char | 可選。規定被視為單詞的特殊字符。 |