Php URL编码IE8与Firefox/Chrome的UTF8字符

Php URL编码IE8与Firefox/Chrome的UTF8字符,php,firefox,internet-explorer-8,Php,Firefox,Internet Explorer 8,在Firefox中,带有特殊字符的URL,如é,会转到 stores.php?id=AsuntosClientes&ansestercombovalue=pérez,Gabriel&limit=25 在IE8中,它是 stores.php?id=asuntosclients&ancesterComboValue=p%C3%A9rez,%20Gabriel&limit=25 在PHP中,使用IE8,$\u GET条目是string(14)”p�雷兹,加布里埃尔“ 对于Firefox,它是:stri

在Firefox中,带有特殊字符的URL,如
é
,会转到

stores.php?id=AsuntosClientes&ansestercombovalue=pérez,Gabriel&limit=25

在IE8中,它是

stores.php?id=asuntosclients&ancesterComboValue=p%C3%A9rez,%20Gabriel&limit=25

在PHP中,使用IE8,$\u GET条目是
string(14)”p�雷兹,加布里埃尔“

对于Firefox,它是:
string(15)“佩雷斯,加布里埃尔”

解决方案是:

if( ! mb_detect_encoding($_GET['ancesterComboValue'], 'UTF-8', true) ){
  $_GET['ancesterComboValue'] = utf8_encode($_GET['ancesterComboValue']);
}
我们必须首先检查字符串是否已经不在UTF8中,否则我们将其从CP1252编码为UTF8

如果我们不检查它,那么它将在Firefox中中断,因为它将重新编码一个已经用UTF8编码的字符串,它看起来像
string(17)“pérez,Gabriel”