這篇文章主要介紹了php簡單統計字符串單詞數量的方法,涉及php字符串分割與數組統計的相關技巧,需要的朋友可以參考下
本文實例講述了php簡單統計字符串單詞數量的方法。分享給大家供大家參考。具體實現方法如下:
- <?php
- function word_count($sentence){
- $array = explode(" ", $sentence);
- return count($array);
- }
- $words = word_count("The is a group of words");
- echo $words;
- ?>
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答