Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $value = str_split(strtolower($_GET["input"]), 1);
- $i = 0;
- $j = 0;
- $fr = [];
- foreach($value as $char){
- if(($char >= 'a' && $char <= 'z')) {
- $i += 1;
- } elseif($char >= '0' || $char <= '9'){
- $j += 1;
- }
- if(array_key_exists($char, $fr)) {
- $v = explode('.', $fr[$char])[1] + 1;
- $fr[$char] = "$char.$v";
- } else {
- $fr[$char] = "$char.1";
- }
- }
- echo "Sono presenti $i vocali e consonanti\n";
- echo "Sono presenti $j caratteri numerici\n";
- foreach($fr as $elem)
- {
- $v = explode(".", $elem)[1] / count($fr) * 100;
- $l = explode(".", $elem)[0];
- echo "Il carattere $l ha frequenza $v%\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement