/ Published in: PHP

This is an regular expression to match an HTML Tag from a given input.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/ To use this expression follow the code below. //Save the expression in a variable. $correct_htmltag_format = "/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/"; //some input from a user through a text field or from a server. $user_input = $_REQUEST['html_tag']; //match the two input's and save it in a variable. //Condition goes here. if(tag_match){ echo "Correct HTML Tag"; } else{ echo "Incorrect HTML Tag"; }
Comments
