本文介绍了php在ie上获取数据编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些表单数据(带get)发送到具有javascript功能的弹出窗口。
这两个页面都有utf-8编码。但弹出显示特殊值错误(如 )。此问题仅在Internet Explorer上发生。当我将ie编码更改为Windows-1254时,它返回正常。页面编码应该保持一致。
使用mb_detect_encoding()检查$ _GET数据;它给出了UTF-8的结果。
任何想法可以导致什么?

 函数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'];


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

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

编辑



我修复了iconv的IE问题。但是现在,这个问题在其他浏览器上开始了。

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

最后编辑



 <?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']; }
}?>


解决方案

检查文件编码。一些文本编辑器如Notepad ++将文件代码内容存储在该编码中。



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



如果它在所有的浏览器中工作,但是IE,你不会去地狱。指责Microsoft和FORGET Internet Explorer。


I m sending some form data (with get) to a popup with a javascript function.Both pages have utf-8 encoding. But popup showing special values wrong (like �). This problem happens on Internet Explorer only. It returns normal when i change ie encoding to windows-1254. Page encoding should stay same.Checked $_GET data with mb_detect_encoding(); it gives UTF-8 result.Any idea what can cause this?

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;
   }

EDIT

I fixed IE problem with iconv. But now, the problem started on other browsers.

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

LAST EDIT

Here is final solution.

<?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']; }
 } ?>
解决方案

Check the file encoding. Some text editors like Notepad++ store the file code content in that encoding.

I think the javascript file is not in UTF-8 encoding.

And if it's working in ALL browsers but IE, you will not go to hell. Blame Microsoft for that and FORGET Internet Explorer.

这篇关于php在ie上获取数据编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 00:04