How to use count chars in PHP
In this article, I will explain how the count_chars() function can be used in PHP.
count_chars() function in PHP
- The count_chars() function is used to return how many times an ASCII character occurs within a string and get the information.
- The count_chars() function is return information about characters used in a string
Syntax
Parameter
- string string is required parameter. it is determine check to string.
-
mode mode is optional parameter. it's default value 0. some different return modes are:
- 0 - an array with the ASCII value as key and number of occurrences as value
- 1 - an array with the ASCII value as key and number of occurrences as value, only lists occurrences greater than zero
- 2 - an array with the ASCII value as key and number of occurrences as value, only lists occurrences equal to zero are listed
- 3 - a string with all the different characters used
- 4 - a string with all the unused characters
Example
The following example show to how the count_chars() function can be used in PHP.
<html>
<body>
<h3 style="color: blue;">count_chars() function example in PHP</h3>
<?php
$str = "C-sharpcorner";
print_r(count_chars($str,0)) ;
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here