<?php
/* 
	Хочу получить
	
<div class="block">
<h1>Первая строчка</h1>
<ul>
<li>Вторая строчка</li>
<li>Третяя строчка</li>
</ul>
</div>
*/

$text = <<<HTML
<ul>
<li>Первая строчка</li>
<li>Вторая строчка</li>
<li>Третяя строчка</li>
</ul>
HTML;

$text = preg_replace("/\<ul\>\n\<li\>(.*?)\<\/li\>/", "/\<h1\>(.*?)\<\/h1\>\n\<ul\>/", $text);
$text = str_replace("<h1>", "<div class='block'><h1>", $text);
$text = str_replace("</ul>", "</ul></div>", $text);
echo $text;
