protected function convertEncoding($string, $destinationEncoding, $sourceEncoding, $useIconv = false)
    {
        if (function_exists('mb_convert_encoding') && !$useIconv) {
            $convertedString = mb_convert_encoding($string, $destinationEncoding, $sourceEncoding);
        } else {
            // I have no excuse for the following. Please forgive me.
            if (is_array($sourceEncoding)) {
                $bestEncoding = '';
                $bestScore    = null;
                foreach ($sourceEncoding as $encoding) {
                    $score = abs(strlen($string) - strlen(@iconv($encoding, $destinationEncoding, $string)));
                    if (is_null($bestScore) || ($score < $bestScore)) {
                        $bestScore    = $score;
                        $bestEncoding = $encoding;
                    }
                }

                $sourceEncoding = $bestEncoding;
            }

            $convertedString = @iconv($sourceEncoding, $destinationEncoding . '//IGNORE', $string);
        }

        return $convertedString;
    }