Advertisement
Fundamentalen

frequent tag

Aug 16th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Most Frequent Tag</title>
  5. </head>
  6. <body>
  7. <p>Enter Tags:</p>
  8. <form action="02.%20MostFrequentTag.php" method="post">
  9.     <input type="text" name="tags">
  10.     <input type="submit" name="submit">
  11. </form>
  12. </body>
  13. </html>
  14.  
  15. <?php
  16. if (isset($_POST['submit'])) {
  17.     $allTags = preg_split('/[\s,]+/', $_POST['tags']);
  18.     $countValues = array_count_values($allTags);
  19.     arsort($countValues);
  20.     $valueChecker = 0;
  21.     $getMaxValueName = "";
  22.     foreach ($countValues as $key => $keyValue) {
  23.         echo("$key : $keyValue times <br>");
  24.         if($keyValue > $valueChecker) {
  25.             $valueChecker = $keyValue;
  26.             $getMaxValueName = $key;
  27.         }
  28.     }
  29.  
  30.     echo("<p>Most Frequent Tag is: $getMaxValueName</p>");
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement