$html_regex = '{ ^( (?: <(\w++) [^>]*+ (? (?1) # matched pair of tags | [^<>]++ # non-tag stuff | <\w[^>]*+/> # self-closing tag | # comment | ]*>.*? # script block )*+ )$ }isx'; if (preg_match($html_regex, $html_string)) echo "block structure seems valid\n"; else echo "block structure seems invalid\n"; ----------------------------------------------------------------------------- Copyright 1997-2024 Jeffrey Friedl