I\'m parsing some messy HTML code with PHP in which there are some redundant
tags and I would like to clean them up a bit. For instance:
&
Here is something you can use. The first line finds whenever there is 2 or more tags (with whitespace between and different types) and replace them with wellformated .
I also included the second line to clean up the rest of the tags if you want that too.
function clean($txt)
{
$txt=preg_replace("{(
|\/>)\s*){2,}}i", "
", $txt);
$txt=preg_replace("{(
|\/>)\s*)}i", "
", $txt);
return $txt;
}