Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport"
  6.           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8.     <title>Document</title>
  9. </head>
  10. <body>
  11.  
  12. <?php
  13.  
  14.  
  15. if (isset($_GET['input'])) {
  16.     $input = strtolower($_GET['input']);
  17.     $pattern = "/[^a-zA-Z]+/";
  18.  
  19.     $input = preg_split($pattern, $input, -1, PREG_SPLIT_NO_EMPTY);
  20.  
  21.  
  22.  
  23.     $out = [];
  24.  
  25.     foreach ($input as $item) {
  26.         if (array_key_exists($item, $out)) {
  27.             $out[$item]++;
  28.         } else {
  29.             $out[$item] = 1;
  30.         }
  31.     }
  32. }
  33.  
  34. $html = "<table border='2'>";
  35.  
  36. foreach ($out as $key => $value){
  37.     $html .= "<tr><td>$key</td><td>$value</td></tr>";
  38. }
  39.  
  40. $html .= "</table>";
  41.  
  42.  
  43.  
  44. echo $html;
  45.  
  46. ?>
  47.  
  48.  
  49. <form>
  50.  
  51.     <input type="text" name="input">
  52.     <input type="submit" value="Count Words">
  53.  
  54. </form>
  55.  
  56. </body>
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement