开发者

Why are these characters in PHP getting converted?

I am getting some information like large amounts of text from the database, but while echoing using PHP, the characters are being changed. How do I get it to display the normal thing? Thanks.

//makes database connection and queries the db
$row = mysqli_fetch_array($result);
echo $row['text'];



  � inside has a question mark
\ before every开发者_如何学编程 apostrophe
and it\\\'s

and more...


First up, the excessive slashes. This is generally caused by over escaping which can be due to magic_quotes, it is suggested to turn it off and use mysql_real_escape_string on the data going into the database. Before you turn it off though, make sure that the data is escaped properly, as this could introduce sql injections exploits in your site.

As far as the weird character. Your database and website character sets need to match. Make sure your website charset is set to utf-8, either with a meta tag or a header setting.

Its a hard change for the magic_quotes, but once it is done, you do not have to worry about using stripslashes on your data again. As you should not have to stripslashes on data coming out of the database, if it was escaped properly in the first place.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜