<?php
header("Content-Type: text/plain; charset=utf-8");
?> 
<?php

mb_internal_encoding("UTF-8");
$text           = <<<TEXT
 <head>
<title>Форма заказа товара</title>
<meta http-equiv="Content-type" content="text/html" charset="windows-1251">
<meta name="keywords" content="">
<meta name="description" content="">
<div>
     <empty>
     </empty>
     <p>
       This is yet another text
       <br/>
       <b><!-- <i> это комментарий --><div class="1"><x это битый тег и он не считается

выведет 
       that wasn't
       <b>
         compliant
       </b>
       <b><!-- <i> это комментарий --><div class="1"><x это битый тег и он не считается

выведет 
       too...
       <br/>
     </p>
     <div class="noClass">
       this one is better but we don't care anyway
     </div>
TEXT;
$commentPattern = "/(<!--).*(-->)/u";
$txt            = preg_replace($commentPattern, '', $text);
$pattern        = "/(<([\w]+)[^>]*>)/";
preg_match_all($pattern, $txt, $new, PREG_SET_ORDER);
foreach ($new as $key => $value) {
    echo $new[$key][2] . "\n";
}
