Return to Snippet

Revision: 21188
at December 6, 2009 12:14 by rupakdhiman


Initial Code
/^<([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.
tag_match = preg_match($correct_htmltag_format, $user_input);

//Condition goes here.
if(tag_match){
  echo "Correct HTML Tag";
}
else{
   echo "Incorrect HTML Tag";
}

Initial URL

                                

Initial Description
This is an regular expression to match an HTML Tag from a given input.

Initial Title
Regular expression to match an HTML Tag

Initial Tags
html

Initial Language
PHP