为什么 PHP 中的这些字符会被转换?

发布于 2024-11-02 04:07:55 字数 284 浏览 0 评论 0原文

我从数据库中获取了一些信息,例如大量文本,但是在使用 PHP 进行回显时,字符正在发生变化。如何让它显示正常的东西?谢谢。

//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

还有更多...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱々樱花落 2024-11-09 04:07:55

首先,过度的斜线。这一般是由于magic_quotes导致的过度转义,建议将其关闭并对进入数据库的数据使用 mysql_real_escape_string 。不过,在关闭它之前,请确保数据已正确转义,因为这可能会在您的站点中引入 SQL 注入漏洞。

至于奇怪的角色。您的数据库和网站字符集需要匹配。确保您的网站字符集设置为 utf-8,使用元标记或 header 设置。

对于magic_quotes来说这是一个艰难的改变,但是一旦完成,您就不必担心使用再次stripslashes您的数据。因为如果一开始就正确转义了数据库中的数据,那么您不必对来自数据库的数据进行stripslashes

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文