PHP count_chars()函數含代碼

    PHP count_chars()函數

    PHP count_chars()是最重要的字符串函數。愛掏網 - it200.com它用于返回字符串中字符的信息。愛掏網 - it200.com

    count_chars(string,mode);
    
    參數 描述 必需/可選
    string 要檢查的字符串 必需
    mode 指定返回模式 可選

    注意:根據’mode’參數的不同,’count_chars()’函數返回以下之一:

    • 0:返回一個以字節值為鍵,每個字節頻率為值的數組。愛掏網 - it200.com
    • 1:與0相同,但只列出頻率大于零的字節值。愛掏網 - it200.com
    • 2:與0相同,但只列出頻率等于零的字節值。愛掏網 - it200.com
    • 3:返回一個包含所有唯一字符的字符串。愛掏網 - it200.com
    • 4:返回一個包含所有未使用字符的字符串。愛掏網 - it200.com

    示例1

    <?php
    str = "Hello World!";
    echo "Your given string: ".str;
    echo "<br>"."By using 'count_chars()' function your string is :".count_chars($str,3);
    ?>
    

    輸出:

    Your given string: Hello World!
    By using 'count_chars()' function your string is : !HWdelor
    

    示例2

    <?php
    data = "Two Ts and one F.";
    foreach (count_chars(data, 1) as i =>val) {
       echo "There were val instance(s) of \"" , chr(i) , "\" in the string.\n";
    }
    ?>
    

    輸出:

    Array ( [32] => 1 [33] => 1 [72] => 1 [87] => 1 [100] => 1 [101] => 1 [108] => 3 [111] => 2 [114] => 1 )
    

    示例3

    <?php
    str = "PHP is Lovely Language!";strArray = count_chars(str,1);
    
    foreach (strArray as key=>value)
       {
       echo "The character <b>'".chr(key)."'</b> was foundvalue time(s)<br>";
       }
    ?>
    

    輸出:

    The character ' ' was found 3 time(s)
    The character '!' was found 1 time(s)
    The character 'H' was found 1 time(s)
    The character 'L' was found 2 time(s)
    The character 'P' was found 2 time(s)
    The character 'a' was found 2 time(s)
    The character 'e' was found 2 time(s)
    The character 'g' was found 2 time(s)
    The character 'i' was found 1 time(s)
    The character 'l' was found 1 time(s)
    The character 'n' was found 1 time(s)
    The character 'o' was found 1 time(s)
    The character 's' was found 1 time(s)
    The character 'u' was found 1 time(s)
    The character 'v' was found 1 time(s)
    The character 'y' was found 1 time(s)
    

    聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
    發表評論
    更多 網友評論0 條評論)
    暫無評論

    返回頂部

    主站蜘蛛池模板: 内射一区二区精品视频在线观看| 国产成人无码精品一区二区三区| 91精品一区二区综合在线| 国产一区二区精品久久| 美女毛片一区二区三区四区| 在线观看一区二区精品视频| 国产主播一区二区| 国产在线一区观看| 99精品一区二区三区无码吞精 | 无码人妻精品一区二区蜜桃AV| 免费一区二区三区| 亚洲一区二区三区电影| 无码人妻视频一区二区三区| 国产激情一区二区三区| 免费无码一区二区| 日韩精品一区二区三区色欲AV| 国产精品视频一区二区三区经| 国模大尺度视频一区二区| 一区二区手机视频| 国产波霸爆乳一区二区| 国产AV午夜精品一区二区三| 农村人乱弄一区二区 | 午夜视频一区二区| 亚洲熟妇av一区| 国产经典一区二区三区蜜芽| 亚洲一区二区在线视频| 免费在线视频一区| 日韩免费无码一区二区三区| 内射白浆一区二区在线观看 | 久久精品午夜一区二区福利| 国产欧美一区二区精品仙草咪 | 无码AV动漫精品一区二区免费| 无码乱人伦一区二区亚洲 | 香蕉久久一区二区不卡无毒影院 | 精品一区二区三区中文字幕| 视频一区二区中文字幕| 亚洲乱码日产一区三区| 日本免费一区二区三区| 国产一区二区精品久久岳√ | 亚洲熟女综合色一区二区三区| 国产自产对白一区|