Count the number of occurrences of the characters in a text, with PHP
The example allows you to count the number of occurrences of the characters in a text.
Code:
<?php
function chars_analyzer( $phrase ) {
$c = count_chars( $phrase, 1 );
while( $i = each( $c ) ) {
$char = chr( $i['key'] );
$frequency = $i['value'];
echo ( "Char: $char - Frequency: $frequency" . "<br />" );
}
}
$phrase = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit";
echo ("Phrase: $phrase");
echo ("<br />");
chars_analyzer( $phrase );
?>
Result of this example: