PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 41: Write a program to count the total number of punctuation characters exists in a string.

punctuation_char.php

<!DOCTYPE html>  
<html> 
<head>	
	<title>PHP Programs TutorialDuniya.com</title>
</head>
<body>  
	<?php  
		$count = 0;  
		$str = "Good Morning! Mr. Abhishek Sharma. Had your breakfast ?";  

		for($i = 0; $i < strlen($str); $i++) 
		{
			if($str[$i] == '!' || $str[$i] == ',' || $str[$i] ==     ';' || $str[$i] == '.'  || $str[$i] == '?' || $str[$i] == '-' || $str[$i] == '\'' || $str[$i] ==   '\"' || $str[$i] == ':') 
			{  
				$count++;  
			}
		}  
	
		echo "Total number of punctuation characters exists in string is : ";  
		echo $count;  
	?>  
</body>  
</html>



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.