开发者

Troubleshooting åäö to åäö

The problem:

An input of åäö in insert åäö in db. The file is in UTF-8 without BOM and comment in the table has utf8_general_ci coallition.

The code:

<?php
    if($_POST['comment']!=''){

            $comment=addcslashes($_POST['comment'], "\x00\n\r\'\x1a\x3c\x3e\x25");


            if($kommentar!=''){
                mysql_query("INSERT INTO comments (comment) VALUES ('$comment')") or die(mysql_error());

            }
        }
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="sv">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    </head>
    <body>
    //Form
    </body>

Background:

Earlier I performed htmlentities on the $_POST['comment']; before inserting to db, and outputted directly, which worked fine. Then I wanted to go best practise and input raw data (just 开发者_如何学运维cleaning) and o htmlentities (or similar) on output. But then I discovered that e.g. åäö is not inputted as åäö but as åäö. Heeeelp :)


You probably need to set the connection's collation to UTF-8, which is iso-8859-1 by default. Try

mysql_set_charset("utf8");

after connecting to the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜