Reputation: 324
i have a very strange phenomena trying to migrate an older php project from iso-8859-1 to utf-8
when typing a german umlaut like "äöüß" into a textfield an submitting it i receive broken ones like "äöüÃ�"
header is set to
<?php header("Content-Type:text/html;charset=UTF-8"); ?>
<meta charset="UTF-8" />
the form is set to
<form accept-charset="utf-8">
and so on - i tried everything i could think of - anybody got an ide or experience with an alike problem?
best regards, Lupo
Upvotes: 3
Views: 2733
Reputation: 188
I'm glad you managed to find a solution. And if you don't want to worry about so many different charset codings or if htmlentities doesn't work for others, here the alternative: I used mysqli DB connection (and PHPV5) Form post for writing/inserting to MySQl DB.
$Notes = $_POST['Notes']; //can be text input or textarea.
$Notes = str_replace('"', '"', $Notes); //double quotes for mailto: emails.
$von = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é"); //to correct double whitepaces as well
$zu = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é");
$Notes = str_replace($von, $zu, $Notes);
echo " Notes:".$Notes."<br>" ;
$Notes = mysqli_real_escape_string($link, $Notes); //for recommended mysqli DB connection.
//$Notes = mysql_real_escape_string($Notes); //for old deprecated mysql DB connection.
// mysqli_real_escape_string Escapes special characters in a string for use in an SQL statement
echo " Notes:".$Notes ; //ready for inserting
//Optinal:
$charset = mysqli_character_set_name($link); //only works for mysqli DB connection printf ("To check your character set but not necessary %s\n",$charset);
Upvotes: 0
Reputation: 324
i found a solution thats working for my case:
i had to change the accept-charset from UTF-8 back to ISO-8859-15 then the field values look ok again - to be able to process the received data i have to utf8_encode them - seems a bit weird but it works fine now.
Thank you all for your time and Jukka for the help.
best regards, Lupo
Upvotes: 1