【问题标题】:php get data encoding on iephp在ie上获取数据编码
【发布时间】:2016-03-20 17:36:17
【问题描述】:

我正在使用 javascript 函数将一些表单数据(使用 get)发送到弹出窗口。 两个页面都有 utf-8 编码。但弹出显示特殊值错误(如 �)。此问题仅在 Internet Explorer 上发生。当我将编码更改为 windows-1254 时,它返回正常。页面编码应该保持不变。 使用 mb_detect_encoding() 检查 $_GET 数据;它给出了 UTF-8 结果。 知道是什么原因造成的吗?

function NewCustomer(field1,field2,field3){
OpenPopup('Customer/New.php?field1='+ field1 +'&field2='+ field2 +'&field3='+ field3 +'', 'NewCustomer', 'channelmode=0, directories=0, fullscreen=0, width=550, height=460, location=0, menubar=0, resizable=0, scrollbars=1, status=0, titlebar=1, toolbar=0', false);
}


echo $_GET['fieldname'];


 function OpenPopup( url, winname, features )
   {
    if(winname==''){
     window.open( url, winname, features, false );
     return;
    }
    if ( !findWindow( url, winname, features ) )
    {
     var handle = window.open( url, winname, features, false );
     if ( handle != null ) handle.focus();
    }
   }

   function findWindow( url, winname, features )
   {
    var handle = window.open( '', winname, features, false );
    if ( handle != null )
    {
     if (( handle.location != 'about:blank' ) && ( handle.location != '' ))
     {
      handle.focus();
      return true;
     }
    }
    return false;
   }

编辑

我用 iconv 修复了 IE 问题。但现在,问题开始出现在其他浏览器上。

iconv('windows-1254', 'UTF-8', $_GET['field']);

最后编辑

这是最终解决方案。

<?php if(isset($_GET['fieldname'])) {
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if (count($matches)>1){ echo iconv('windows-1254', 'UTF-8', $_GET['fieldname']); } else { echo $_GET['fieldname']; }
 } ?>

【问题讨论】:

标签: php encoding get


【解决方案1】:

在你的 $_GET 变量中,使用这个:

echo utf8_encode($_GET['my_var']);

echo utf8_decode($_GET['my_var']);

更新:我测试过,看起来不错

echo iconv("UTF-8", "ISO-8859-1//TRANSLIT", $field);

希望对你有帮助;)

感谢。

【讨论】:

  • utf8_decode 使 � > ? utf8_encode 使 � > ð 或 þ (根据字符)都不能修复。
  • 是的,地址栏没问题。 New.php?field=şğç
【解决方案2】:

检查文件编码。一些文本编辑器(如 Notepad++)以该编码存储文件代码内容。

我认为 javascript 文件不是 UTF-8 编码的。

如果它可以在除 IE 之外的所有浏览器中运行,您将不会下地狱。责备微软并忘记 Internet Explorer。

【讨论】:

  • 选中,两个页面都使用 UTF-8 编码,没有 BOM。 Javascript 在同一页面中。也尝试将 charset="utf-8" 添加到 js 中。
猜你喜欢
  • 1970-01-01
  • 2021-12-31
  • 2016-09-14
  • 1970-01-01
  • 2016-10-09
  • 2019-02-08
  • 1970-01-01
  • 1970-01-01
  • 2015-09-28
相关资源
最近更新 更多