I got an error by this regular expression...
$strTmp = preg_replace(\'~(<\\/CharacterStyleRange>(.*?)\\n*)~gim \' , \">
There is a / before the letter G in the string you're replacing.
/