Не вырезал, а пересобрал =)
<?php
$HTMLCode = <<< HTML
<div onclick="alert('Hello')" style="color:#ff0000;">текст1</div>
<div onclick="alert('Hello')">текст2</div>
<div style="color:#ff0000;" onclick="alert('Hello')">текст3</div>
<div style="color:#ff0000;">текст4</div>
HTML;
$HTMLCode = mb_convert_encoding($HTMLCode, 'HTML-ENTITIES', "UTF-8");
$dom = new DomDocument();
$dom->loadHTML( $HTMLCode );
$xpath = new DomXPath( $dom );
$_res = $xpath->query(".//div");
foreach($_res as $div){
$style = $div->getAttribute('style') ? ' style="'.$div->getAttribute('style').'"' : '';
echo '<div'.$style.'>'.$div->textContent.'</div>';
}