I got an error by this regular expression...
$strTmp = preg_replace(\'~(<\\/CharacterStyleRange>(.*?)\\n*)~gim \' , \">
g is implicit with preg_replace(). You don't need to include it.
g
preg_replace()