Guest User

Untitled

a guest
Mar 3rd, 2017
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2. if (isset($_GET["input"]) && !empty(trim($_GET["input"]))) {
  3.     $text = trim($_GET["input"]);
  4.     preg_match_all("/[a-zA-Z]+/", $text, $words);
  5.     $words = array_map("strtolower", $words[0]);
  6.     $wordsCount = [];
  7.     foreach ($words as $word) {
  8.         if (!array_key_exists($word, $wordsCount)) {
  9.             $wordsCount[$word] = 0;
  10.         }
  11.         $wordsCount[$word]++;
  12.     }
  13.     echo buildTable($wordsCount);
  14. }
  15. function buildTable($items) {
  16.     $output = "<table border='2'>";
  17.     foreach ($items as $key => $val) {
  18.         $output .= "<tr><td>{$key}</td><td>{$val}</td></tr>";
  19.     }
  20.     $output .= "</table>";
  21.     return $output;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment