I found a solution which works for me. I replaced the line:
$result = chr(239) . chr(187) . chr(191) . $result;
with:
$result = iconv("UTF-8", "CP1252", $result);
MichaelZ70 (talk)