php str_word_count 函數執行個體教程

來源:互聯網
上載者:User

定義和用法
該str_word_count ( )函數計數的數目字一個字串。

文法

str_word_count(string,return,char)
ParameterDescription
string
必需的。指定的字串檢查
return
任擇。指定傳回值的str_word_count ( )函數。可能值: 0 -預設。返回字數發現1 -返回一個數組的話從字串2 -返回一個數組在關鍵的立場是,這個詞的字串,和價值是實際的字
char
任擇。指定特殊字元將被視為話。註:此參數是說在PHP 5.1
我們來看執行個體.
<?phpecho str_word_count("Hello world!");?>
輸出為2
 
下面再看.
 
<?phpprint_r(str_word_count("Hello world!",1));?>
 
結果.
 
Array([0] => Hello[1] => world)
 
再看.
 
<?phpprint_r(str_word_count("Hello world!",2));?>
 
輸出結果
 
Array([0] => Hello[6] => world)
 

樣本4
str_word_count ( )不與焦炭參數:

 

<?phpprint_r(str_word_count("Hello world & good morning!",1));print_r(str_word_count("Hello world & good morning!",1,"&"));?>
 
輸出.
 
Array([0] => Hello[1] => world[2] => good[3] => morning)
Array([0] => Hello[1] => world[2] => &[3] => good[4] => morning)
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.