$return .= "&#".hexdec(bin2hex(mb_convert_encoding($string{$i},"Unicode","UTF-8"))).";";

$return .= "&#".hexdec(bin2hex(mb_convert_encoding(mb_substr($string,$i,1,"UTF-8"),"Unicode","UTF-8"))).";";
マルチバイト考慮してなかったわ、、頭が回ってないな