首页 > Web开发 > 详细

php字符串英文文本中大写字母,小写字母,空格,标点符号的个数统计

时间:2017-11-05 12:05:57      阅读:239      评论:0      收藏:0      [点我收藏+]

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

<?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>";
?>

 

php字符串英文文本中大写字母,小写字母,空格,标点符号的个数统计

原文:http://www.cnblogs.com/Wang-Y/p/7786902.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!