开发者

Why are these characters in PHP getting converted?

开发者 https://www.devze.com 2023-02-25 04:21 出处:网络
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.

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

精彩评论

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

关注公众号