Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 2. Count of Letters
- //Write a program that reads a list of letters and prints for each letter how many times it appears in the list. The letters should be //listed in alphabetical order. Use the input and output format from the examples below.
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <form method="post" action="CountLetters.php">
- <input type="text" name="str1">
- <input type="submit" value="GO">
- </form>
- </body>
- </html>
- <?php
- $string1=$_POST['str1'];
- $arr1 = explode(" ", $string1);
- sort($arr1);
- for($i=0;$i<=count($arr1)-1;$i++){
- if ($arr1[$i]==$arr1[$i+1]){
- if (!(isset($output[$arr1[$i]]))) {
- $output[$arr1[$i]]=1;
- }
- $output[$arr1[$i]]+=1;
- }
- }
- foreach($output as $k=>$v){
- echo $k.'->'.$v.'<br>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment