Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--Write a PHP script HTMLTagsCounter.php which generates an HTML form like in the example below. It should contain a label, an input text field and a submit button. The user enters HTML tag in the input field. If the tag is valid, the script should print “Valid HTML tag!”, and if it is invalid – “Invalid HTML Tag!”. On the second line, there should be a score counter. For every valid tag entered, the score should increase by 1.
- Hint: You may use sessions. Use an array to store all valid HTML5 tags.-->
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta content="text/html" charset="UTF-8">
- <title>HTML Tags Counter</title>
- </head>
- <body>
- <form action="#" method="post">
- <p><label for="htmlTag">Enter HTML tags:</label></p>
- <p><input type="text" name="htmlTag" id="htmlTag"/>
- <input type="submit" value="Submit"/>
- </p>
- </form>
- <?php
- session_start();
- if ($_POST && array_key_exists('htmlTag', $_POST)) {
- $validHTML5Tags = array('!--...--', '!DOCTYPE', 'a', 'abbr', 'address', 'area', 'article', 'aside', 'audio',
- 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite',
- 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog',
- 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form',
- 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe',
- 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'main', 'map',
- 'mark', 'menu', 'menuitem', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup',
- 'option', 'output', 'p', 'param', 'pre', 'progress', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby',
- 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style',
- 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th',
- 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr');
- if (!array_key_exists('counter', $_SESSION)) {
- $_SESSION['counter'] = 0;
- }
- $checkTag = 'Invalid';
- if (in_array($_POST['htmlTag'], $validHTML5Tags)) {
- $checkTag = 'Valid';
- $_SESSION['counter'] += 1;
- }
- echo "<p>$checkTag HTML tag!</p>\n<p>Score: " . $_SESSION['counter'] . "</p>\n";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement