PHP count_chars() Function
In this chapter you will learn:
- Definition for PHP count_chars() Function
- Syntax for PHP count_chars() Function
- Parameter for PHP count_chars() Function
- Return for PHP count_chars() Function
- Example - Get the caracter count
Definition
The count_chars()
function returns an array containing
the letters used in that string and how many times each letter was used.
Syntax
PHP count_chars() function has the following syntax.
mixed count_chars ( string str [, int mode] )
Parameter
If the mode parameter is 1, only letters with a frequency greater than 0 are listed; if the mode parameter is 2, only letters with a frequency equal to 0 are listed.
Return
PHP count_chars() function returns the character count.
Example
Get the caracter count
<?PHP//from j av a 2 s. c o m
$str = "This is a test from java2s.com.";
$a = count_chars($str, 1);
print_r($a);
?>
In that output, ASCII codes are used for the array keys, and the frequencies of each letter are used as the array values.
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Description for PHP crc32() Function
- Syntax for PHP crc32() Function
- Parameter for PHP crc32() Function
- Example for PHP crc32(string)
Home » PHP Tutorial » PHP String Functions