public static function toASCII($str, $charset = 'UTF-8')
    {
        $asciistr = '';
        if (mb_detect_encoding($str, 'UTF-8', true) === false) {
            $str = utf8_encode($str);
        }

        if (version_compare(PHP_VERSION, '5.6.0') < 0) {
            iconv_set_encoding('input_encoding', 'UTF-8');
            iconv_set_encoding('internal_encoding', 'UTF-8');
            iconv_set_encoding('output_encoding', $charset);
        }

        $str = html_entity_decode($str, ENT_QUOTES, $charset);
        $strlen = iconv_strlen($str, $charset);
        for ($i = 0; $i < $strlen; $i++) {
            $char = iconv_substr($str, $i, 1, $charset);
            if (!preg_match('/[`\'^~"]+/', $char)) {
                if ('UTF-8' === $charset) {
                    $asciistr .= preg_replace('/[`\'^~"]+/', '', iconv($charset, 'ASCII//TRANSLIT//IGNORE', $char));
                } else {
                    $asciistr .= preg_replace('/[`\'^~"]+/', '', iconv('UTF-8', $charset.'//TRANSLIT//IGNORE', $char));
                }
            } else {
                $asciistr .= $char;
            }
        }

        return $asciistr;
    }