";
?>
String Processing Application
String Processing Application
";
// As long as there are double spaces inside of the string, kill them
// If you wanted to remove tabs and such, you could do it using the same
// while loop except that you would search for tabs instead of double
// spaces and replace them with a single space
while($position = strpos($trimmed_str, " "))
{
$trimmed_str = substr_replace($trimmed_str, ' ', $position, 2);
}
// Now that the string is cleaned up, a simple set of string functions
// will count the parameters for you.
print "\n";
print "- The trimmed string has ".strlen($trimmed_str)." characters.";
$word_array = explode (" ", $trimmed_str);
print "
- The trimmed string has ".count($word_array)." words.";
$sentence_array = explode (".", $trimmed_str);
$number_of_sentences = count($sentence_array) - 1;
print "
- The trimmed string has ".$number_of_sentences." sentences.";
?>