如果你不想擔心SO 3 M任何不同的字符集編碼或如果htmlentities不適合你,這裏的替代: 我用mysqli數據庫連接(和PHPV5)表單發佈寫入/插入到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
enter code here
//Optional:
$charset = mysqli_character_set_name($link); //only works for mysqli DB connection
printf ("To check your character set but not necessary %s\n",$charset);
確保您的編碼不被apache或htaccess強制執行。我已經看到類似的情況,即使在meta中選擇utf-8,編碼也會有所不同。爲此你需要改變htaccess。您可以通過點擊瀏覽器上的編碼進行檢查,並查看您查看網站時選擇的內容。還有meta格式: – 2012-07-11 11:55:40
你沒有說它來自數據庫。使你的數據庫連接是UTF-8,你可以通過utf-8到htmlentities – 2012-07-11 11:58:14