<?php
function html_ucfirst($s) {
    return preg_replace_callback('#^((<(.+?)>)*)(.*?)$#', function ($c) {
            return $c[1].ucfirst(array_pop($c));
    }, $s);
}
$string= "<p>Lorem IPSUM is simply dummy text. LOREM ipsum is simply dummy text! wHAt is LOREM IPSUM? Hello lorem ipSUM!</p>";
echo html_ucfirst($string);
?>
