防止PHP DomDocument loadHTML()删除由于实体编码而导致的字符

I am using PHP DomDocument to parse my code so anything in a <code> block gets htmlspecialchars() encoded. However, the loadHTML() method is doing some weird things to my string. On a tag like this <Tag *:35>, it removes everything after the asterisk, along with lowercasing the first letter. If I do htmlspecialchars(), right before loadHTML(), then it prevent this from happening, but then entity encodes my ENTIRE page which is not my intended result. I simply want it to do this to everything my code tag, which it is already doing pretty much perfectly. It's just this one weird behavior.