count_chars() function will return information about characters used in a string, which can be string with all different characters, with all unused characters and details of ASCII values as key and number of occurrences as a value etc. Please see mode parameter for more information
string – String to be checked.
mode – This is Optional parameter, It defines the return mode. 0 is the default value. Here are the return modes values which can be used
This will return information depending upon the mode passed Or for the default mode value which is 0 (zero).
Related articles : substr_count(), str_word_count(), strlen().
<?php $strExample = "Hi from tutorialmines.net!"; echo count_chars($strExample,3); ?>
In above example ,We have a string “Hi from tutorialmines.net!”. So, when we apply count_chars() function. This will a string with all the different characters used in it.
Now Output will become –
<?php $strExample = count_chars("Hi from tutorialmines.net",4); echo($strExample); ?>
In above example ,We have a string “Hi from tutorialmines.net!”. So, when we apply count_chars() function. This will return a string with all the unused characters .
Output will be like below:
In this example we will use count_chars() with mode 1 to check the string.
<?php $str = "Hi from tutorialmines.net!"; print_r(count_chars($str,1)); ?>
In above example ,We have a string “Hi from tutorialmines.net!”. So, when we apply count_chars() function. This will return an array with the ASCII value as key and how many times it occurred as value: with all the unused characters .
Output will be like below:
<?php $str = "Hi from tutorialmines.net!"; $strArray = count_chars($str,1); foreach ($strArray as $key=>$value) { echo "The character <b>'".chr($key)."'</b> was found $value time(s)<br>"; } ?>
In above example ,We have a string “Hi from tutorialmines.net!”. So, when we apply count_chars() function. This will return an array with the ASCII value as key and how many times it occurred as value: with all the unused characters .
Output will be like below:
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…