I need to detect whether a string contains HTML tags.
if(!preg_match(\'(?<=<)\\w+(?=[^<]*?>)\', $string)){
return $string;
}
If purpose is just to check if string contain html tag or not. No matter html tags are valid or not. Then you can try this.
function is_html($string) {
// Check if string contains any html tags.
return preg_match('/<\s?[^\>]*\/?\s?>/i', $string);
}
This works for all valid or invalid html tags. You can check confirm here https://regex101.com/r/2g7Fx4/3