zoukankan      html  css  js  c++  java
  • php字符串英文文本中大写字母,小写字母,空格,标点符号的个数统计

    对一段英文文本的信息,统计其中大写字母,小写字母,空格,标点符号的个数

    <?php
    $manuscript = "Where there is a will, there is a way.";//字符串文本
    $smallLetter = 0;
    $capitalLetter = 0;
    $blank = 0;
    $punctuation = 0;

    $num=strlen($manuscript);
    $arr=str_split($manuscript);//字符串分割为数组
    foreach($arr as $key=>$value)
    {
    if($value==' ')
    {
    $blank+=1;
    }
    if('a'<=$value&&$value<='z')
    {
    $smallLetter+=1;
    }
    if('A'<=$value&&$value<='Z')
    {
    $capitalLetter+=1;
    }
    }
    $punctuation=$num-$smallLetter-$capitalLetter-$blank;


    echo '小写字母个数:'.$smallLetter."<br>";
    echo '大写字母个数:'.$capitalLetter."<br>";
    echo '空格个数:'.$blank."<br>";
    echo '标点个数:'.$punctuation."<br>";
    ?>

  • 相关阅读:
    工具
    选择排序
    c#中queue的用法
    c#加密
    话谈c#拷贝
    const与readonly的区别
    WinForm中使MessageBox实现可以自动关闭功能
    c#winform关闭窗口时触发的事件
    委托
    C# STA和MTA线程设置
  • 原文地址:https://www.cnblogs.com/Wang-Y/p/7786902.html
Copyright © 2011-2022 走看看