Detect HTML tags in a string

前端 未结 8 1484
渐次进展
渐次进展 2020-12-04 12:59

I need to detect whether a string contains HTML tags.

if(!preg_match(\'(?<=<)\\w+(?=[^<]*?>)\', $string)){ 
    return $string;
}
8条回答
  •  我在风中等你
    2020-12-04 13:42

    A simple solution is:

    if($string != strip_tags($string)) {
        // contains HTML
    }
    

    The benefit of this over a regex is it's easier to understand, however I could not comment on the speed of execution of either solution.

提交回复
热议问题