Reputation: 460
I got a database that contains accented letters (like "é" etc) in several fields. If I echo those on my pages they are displayed correctly, because I use this html-tag when I render my html:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
But when I want to display a value from a parameter from my URL with $_GET it doesn't work.
I use this code:
$fname = $_GET['fname'];
Actual output:
groté
Desired output:
Groté
The encoding looks OK to me, I checked it using this code:
var_dump($fname);
var_dump(iconv_get_encoding('all'));
Output:
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" }
I don't use code where I set the encoding in php. I only use the meta tag, like noted above.
What's wrong with my code?
Upvotes: 0
Views: 140
Reputation: 460
OK, after further investigation I found a solution!
$fnameraw = $_GET['fname'];
$fname = utf8_decode($fnameraw);
Now I got the correct output: groté ! While using charset=ISO-8859-1 in my meta tag. Both the database-output as the output from the URL display correctly.
Upvotes: 1