add check for mb_ function compat and fallback
updated version
decode special chars after entity replace, fixes bug in entity replacement
updated version
added braces to if statement for clarity
convert missing variables to $instance
updated version