PHP count_chars()函數(shù)講解
PHP count_chars() 函數(shù)
實(shí)例
返回一個(gè)字符串,包含所有在 "Hello World!" 中使用過的不同字符(模式 3):
<?php $str = "Hello World!"; echo count_chars($str,3); ?>
定義和用法
count_chars()
函數(shù)返回字符串所用字符的信息(例如,ASCII 字符在字符串中出現(xiàn)的次數(shù),或者某個(gè)字符是否已經(jīng)在字符串中使用過)。
語法
count_chars( _string,mode_ )
實(shí)例 1
返回一個(gè)字符串,包含所有在 "Hello World!" 中未使用過的字符(模式 4):
<?php $str = "Hello World!"; echo count_chars($str,4); ?>
實(shí)例 2
在本實(shí)例中,我們將使用 count_chars() 來檢查字符串,返回模式設(shè)置為 1。模式 1 將返回一個(gè)數(shù)組,ASCII 值為鍵名,出現(xiàn)的次數(shù)為鍵值:
<?php $str = "Hello World!"; print_r(count_chars($str,1)); ?>
實(shí)例 3
統(tǒng)計(jì) ASCII 字符在字符串中出現(xiàn)的次數(shù)另一個(gè)實(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>"; } ?>
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
相關(guān)文章
BS結(jié)構(gòu)中使用PHP訪問ORACLE LOB
這篇文章主要介紹了BS結(jié)構(gòu)中使用PHP訪問ORACLE LOB2006-10-10優(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