PHP count_chars()函數(shù)講解
PHP count_chars() 函數(shù)
實例
返回一個字符串,包含所有在 "Hello World!" 中使用過的不同字符(模式 3):
<?php $str = "Hello World!"; echo count_chars($str,3); ?>
定義和用法
count_chars()
函數(shù)返回字符串所用字符的信息(例如,ASCII 字符在字符串中出現(xiàn)的次數(shù),或者某個字符是否已經(jīng)在字符串中使用過)。
語法
count_chars( _string,mode_ )
實例 1
返回一個字符串,包含所有在 "Hello World!" 中未使用過的字符(模式 4):
<?php $str = "Hello World!"; echo count_chars($str,4); ?>
實例 2
在本實例中,我們將使用 count_chars() 來檢查字符串,返回模式設置為 1。模式 1 將返回一個數(shù)組,ASCII 值為鍵名,出現(xiàn)的次數(shù)為鍵值:
<?php $str = "Hello World!"; print_r(count_chars($str,1)); ?>
實例 3
統(tǒng)計 ASCII 字符在字符串中出現(xiàn)的次數(shù)另一個實例:
<?php $str = "PHP is pretty fun!!"; $strArray = count_chars($str,1); foreach ($strArray as $key=>$value) { echo "The character <b>'".chr($key)."'</b> was found $value time(s)<br>"; } ?>
總結
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內(nèi)容請查看下面相關鏈接
相關文章
優(yōu)化NFR之一 --MSSQL Hello Buffer Overflow
優(yōu)化NFR之一 --MSSQL Hello Buffer Overflow...2006-10-10PHP has encountered an Access Violation
PHP has encountered an Access Violation...2007-01-01