radanser,
Please enclose any code between [ code] and [ /code] or [ php] and [ /php] bbcode tags. (it keeps proper formatting).
I found this function on the net somewhere generally used for preg_replace() (to REMOVE html) and I have adapted it a little for preg_match_all() which will return all of the matches into an array.
<?php
$str = "<h2>Some title</h2>
<p>Some random text</p>
<ul>
<li>List item 1</li>
<li><a href=\"link.php\">List item 2</a></li>
</ul>";
$regex = "/<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/i";
$html = array();
$zx = preg_match_all($regex,$str,$html);
$fixedstr = implode("\n",$html[0]);
printf("<pre>%s</pre>",htmlentities($fixedstr));
?>
This should get you on the right track - you can always search for other functions that remove HTML code and replace the regex.
Good Luck...