PHP Programs

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

Program 45: Write a program to count the total number of characters in a string.

total_char.php

<!DOCTYPE html>  
<html>  
<head>	
	<title>PHP Programs TutorialDuniya.com</title>
</head>
<body>  
	<?php  
		$str1 = "Hard Work Pays Off !";  
		$count = 0;  

		for($i = 0; $i < strlen($str1); $i++) 
		{  
			if($str1[$i] != ' ')  
			$count++;  
		} 
		
		echo "Original string is  : ". $str1;

		echo "Total number of characters in a string: " . $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.