<?php
function replace_between($str, $needle_start, $needle_end, $replacement) {
$pos = strpos($str, $needle_start);
$start = $pos === false ? 0 : $pos + strlen($needle_start);
$pos = strpos($str, $needle_end, $start);
$end = $start === false ? strlen($str) : $pos;
return substr_replace($str,$replacement, $start, $end - $start);
}
$string = '<div class="header-top clearfix">Текст</div>';
echo replace_between($string, '<div class="header-top clearfix">', '</div>', 'Замененный текст');