dongsuo0517 2015-07-15 12:56
浏览 77

PHP UTF-8 mb_convert_encode和Internet-Explorer

Since some days I read about Character-Encoding, I want to make all my Pages with UTF-8 for Compability. But I get stuck when I try to convert User-Input to UTF-8, this works on all Browsers, expect Internet-Explorer (like always).

I don't know whats wrong with my code, it seems fine to me.

  • I set the header with char encoding
  • I saved the file in UTF-8 (No BOM)

This happens only, if you try to access to the page via $_GET on the internet-Explorer myscript.php?c=äüöß When I write down specialchars on my site, they would displayed correct.

This is my Code:

// User Input
$_GET['c'] = "äüöß"; // Access URL ?c=äüöß
header("Content-Type: text/html; charset=utf-8");

$_GET = userToUtf8($_GET);

function userToUtf8($string) {
    if(is_array($string)) {
        $tmp = array();
        foreach($string as $key => $value) {
            $tmp[$key] = userToUtf8($value);
        return $tmp;

    return userDataUtf8($string);

function userDataUtf8($string) {
    print("1: " . mb_detect_encoding($string) . "<br>"); // Shows: 1: UTF-8
    $string = mb_convert_encoding($string, 'UTF-8', mb_detect_encoding($string)); // Convert non UTF-8 String to UTF-8
    print("2: " . mb_detect_encoding($string) . "<br>"); // Shows: 2: ASCII
    $string = preg_replace('/[\xF0-\xF7].../s', '', $string);
    print("3: " . mb_detect_encoding($string) . "<br>"); // Shows: 3: ASCII

    return $string;
echo $_GET['c']; // Shows nothing
echo mb_detect_encoding($_GET['c']); // ASCII
echo "äöü+#"; // Shows "äöü+#"

The most confusing Part is, that it shows me, that's converted from UTF-8 to ASCII... Can someone tell me why it doesn't show me the specialchars correctly, whats wrong here? Or is this a Bug on the Internet-Explorer?

Edit: If I disable converting it says, it's all UTF-8 but the Characters won't show to me either... They are displayed like "????"....

Note: This happens ONLY in the Internet-Explorer!

  • 写回答

2条回答 默认 最新


      相关推荐 更多相似问题


      • ¥20 如何按照企业名字进行爬虫
      • ¥15 关于#单片机#的问题,如何解决?
      • ¥100 制作短链接和api接口的
      • ¥15 星河亮点sp9500测试指导
      • ¥15 dataframe 某列数据分列
      • ¥15 风扇导入fluent后仿真压力和速度数据卡在旋转域
      • ¥15 echarts中dataZoom报错
      • ¥15 求解答:《前端综合基础》作为一门课程的话,应该包含哪些内容?
      • ¥15 软件原型系统开发+实例测试
      • ¥50 C#上位机调试Win USB