Convert to Unicode before substituting

Fixes a bug whereby phptidy failed if input text was beyond ASCII