Is this what you want?
Input:
text <a href="index.html">text</a> html
Output:
text <a href="index.html">text</a> xhtml
I couldn't find a way to do that in one replace, so i used the e-modifier:
$str = preg_replace('/>[<]html[<]</ie', "preg_replace('/html/i', 'xhtml', '\0')", $str);