dshdb64088 2012-04-02 10:57
浏览 58
已采纳

差异Firefox - Chrome编码变音符号时

Chrome converts this: aöüß to %C3%A4%C3%B6%C3%BC%C3%9F But Firefox converts it to this strange thing here: a%F6%FC%DF I can't seem to find a way to convert the Firefox thing back to the original in PHP. Urldecode and rawurldecode unfortunately don't work. Does anyone know how to deal with that? Thanks.

  • 写回答

2条回答 默认 最新

  • douci2022 2012-04-02 11:28
    关注

    As Tei already guessed: Chrome is using UTF-8 (as probably recommended) for URL parameters while Firefox uses Latin-1. I don't think that you can control this behavior. Also this will be difficult to handle, because you pretty much need to guess the encoding that was used.

    This is how the decoding works (browser-dependent, assuming that you're using UTF-8 in your application):

    Chrome:

    $text = urldecode($_GET['text']);
    

    Firefox:

    $text = utf8_encode(urldecode($_GET['text']));
    

    This may be a solution that works in most cases:

    function urldecode_utf8($text) {
        $decoded = urldecode($text);
    
        if (!mb_check_encoding($decoded, 'UTF-8')) {
            $decoded = utf8_encode($decoded);
        }
    
        return $decoded;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发