PHP 正则表达式以匹配HTML标记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 正则表达式以匹配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.
tag_match = preg_match($correct_htmltag_format, $user_input);

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

以上是关于PHP 正则表达式以匹配HTML标记的主要内容,如果未能解决你的问题,请参考以下文章