Home >>PHP String Functions >PHP count_chars() Function

PHP count_chars() Function

PHP count_chars() Function

The PHP count_chars() functionis used in PHP to get all the information related to the characters present in the given input string. This is an in-built function of PHP. Using this ount_char() function, we can get different information about the input string, like the number of times a character occur in the given string, all the ASCII characters that are not present in the string.

Syntax :

count_chars(string,return_mode)

Let's see some examples for this function:

<html>
<body>
<?php
$str = "PHP is a server side scripting language. that is used to develop Static websites or Dynamic websites or Web applications.";
echo count_chars($str,3);
?> 
</body>
</html>
Output:
.DHPSWabcdeghilmnoprstuvwy

Example 2

<html>
<body>
<?php
$str = "PHP is a server side scripting language. that is used to develop Static websites or Dynamic websites or Web applications.";
print_r(count_chars($str,1));
?>  
</body>
</html>
Output:
Array ( [32] => 19 [46] => 2 [68] => 1 [72] => 1 [80] => 2 [83] => 1 [87] => 1 [97] => 8 [98] => 3 [99] => 4 [100] => 3 [101] => 12 [103] => 3 [104] => 1 [105] => 11 [108] => 3 [109] => 1 [110] => 4 [111] => 5 [112] => 4 [114] => 5 [115] => 11 [116] => 9 [117] => 2 [118] => 2 [119] => 2 [121] => 1 )

Popular Tutorials