php $ _GET无法正常使用ISO-8859-1字符

时间:2015-12-28 15:22:58

标签: php encoding character-encoding get iso-8859-1

我有一个数据库,其中包含几个字段中的重音字母(如“é”等)。如果我在我的页面上回显它们,它们会正确显示,因为我在渲染我的html时使用了这个html标签:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

但是当我想使用$ _GET显示来自我的网址的参数中的值时,它不起作用。

我使用此代码:

$fname = $_GET['fname'];

实际输出:

groté

期望的输出:

Groté

编码看起来不错,我使用此代码检查了它:

var_dump($fname);
var_dump(iconv_get_encoding('all'));

输出:

string(6) "groté" 
array(3) { ["input_encoding"]=> string(10) "ISO-8859-1" ["output_encoding"]=> string(10) "ISO-8859-1" ["internal_encoding"]=> string(10) "ISO-8859-1" }

我不使用我在php中设置编码的代码。我只使用meta标签,如上所述。

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:1)

好的,经过进一步调查,我找到了解决方案!

$fnameraw = $_GET['fname'];
$fname = utf8_decode($fnameraw);

现在我得到了正确的输出:groté! 在我的元标记中使用charset = ISO-8859-1。数据库输出作为URL的输出都正确显示。