标签:for letter where amp 个数 信息 foreach each script
对一段英文文本的信息,统计其中大写字母,小写字母,空格,标点符号的个数
<?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字符串英文文本中大写字母,小写字母,空格,标点符号的个数统计
标签:for letter where amp 个数 信息 foreach each script
原文地址:http://www.cnblogs.com/Wang-Y/p/7786902.html