For information about an English text, count the number of uppercase letters, lowercase letters, spaces, and punctuation marks.
<?php
$manuscript = "Where There is a would, there is a."; /string literal
$smallLetter = 0;
$capitalLetter = 0;
$blank = 0;
$punctuation = 0;
$num =strlen ($manuscript);
$arr =str_split ($manuscript);//string split into arrays
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 ' Lowercase letter number: '. $smallLetter. " <br> ";
Echo ' Number of capitals: '. $capitalLetter. " <br> ";
Echo ' Number of spaces: '. $blank. " <br> ";
Echo ' Punctuation number: '. $punctuation. ' <br> ";
?>
PHP string The number of uppercase letters, lowercase letters, spaces, punctuation numbers in English text