Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--Write a PHP script MostFrequentTag.php which generates an HTML input text field and a submit button.
- In the text field the user must enter different tags, separated by a comma and a space (", ").
- When the information is submitted, the script should generate a list of the tags, sorted by frequency.
- Then you must print: "Most Frequent Tag is: [most frequent tag]". Semantic HTML is required.
- Styling is not required.-->
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta content="text/html" charset="UTF-8">
- <title>Most Frequent Tag</title>
- </head>
- <body>
- <form action="#" method="get">
- <p><label for="tags">Enter Tags:</label></p>
- <input type="text" name="tags" id="tags" required/>
- <input type="submit" value="Submit"/>
- </form>
- <?php
- if ($_GET && $_GET['tags']) {
- $tags = explode(', ', trim($_GET['tags']));
- $tags = array_count_values($tags);
- arsort($tags);
- foreach ($tags as $key => $value) {
- echo '<p>' . htmlspecialchars($key) . " : $value times</p>\n";
- }
- $keys = array_keys($tags);
- echo '<p>Most Frequent Tag is: ' . htmlspecialchars($keys[0]) . "</p>\n";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement