VanessaShopping

Word Mapping

Feb 5th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2. if (isset($_GET['input']) && !empty($_GET['input'])) {
  3. $inputText = trim(strtolower($_GET['input']));
  4. $inputText = preg_replace('/\s+/', ' ', $inputText); // Заменяме всички whitespace с един space
  5. $text = explode(" ", $inputText);
  6. $text = preg_replace('/[^A-Za-z\-]/', '', $text);
  7. $result;
  8. foreach ($text as $word) {
  9.     if (!($word == "")) {
  10.         $result[] = $word;
  11.     }
  12. }
  13. $output = array_count_values($result);
  14. ?>
  15. <table border='2'><?php foreach ($output as $key => $value) : ?>
  16. <tr><td><?= $key ?></td><td><?= $value ?></td></tr><?php endforeach;
  17.     } ?></table>
Advertisement
Add Comment
Please, Sign In to add comment