php get data encoding on ie

2019-08-18 20:46发布

问题:

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

回答1:

In you $_GET var, use this:

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

or

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

Update: I tested with, and looks fine

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

I hope it helps ;)

Saludos.



回答2:

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 encoding get