-2

我有一个名为 $data 的数组,我将此数据发送到我的数据库插入方法。

与以下内容一起使用时效果很好:

'body' => $_POST['body']

但是,当我尝试:

'body' => htmlentities($_POST['body'])

只保存了前 3 个单词,但当涉及字符ě时,它停在那里,文本的其他部分没有保存。

在我的数据库中,正文存储在标准文本类型 utf_8_general_ci 的正文列中。

我猜它与数据库设置无关,因为所有表都设置为 uf8_general_ci 以及表本身(与我的本地主机相同)。

最有趣的部分是,在我运行 wamp 的 localhost 机器上,它与所有这些奇怪的字符一起工作,并且在唱 htmlentities 时文本被正确保存。

只有在服务器上它不起作用。顺便提一句。如果有帮助,它只是主机。

您知道如何以与我的 localhost 或除 htmlentities 之外的任何其他功能相同的方式运行它吗?

我需要 htmlentities,因为我有像谷歌地图这样的 html 代码,它需要保存。如果没有 htmlentities,它会被错误地保存。

4

3 回答 3

1

在插入数据库时​​尝试使用 mysql_real_escape_string 或 mysqli_real_escape_string 或准备好的语句。

于 2013-03-24T09:20:14.770 回答
0

Try and set the htmlentities encoding to match your form data encoding.

Note the dividing PHP version 5.4.0: default encoding for htmlentities can be UTF-8 or ISO-8859-1. Does your local machine have the same PHP version as server?

Note to all local machine users (MAMP, WAMP, LAMP, whatever): always check your PHP/MySQL versions if they match the server version. There is almost always some common function that doesn't work as expected when the testing environment isn't identical to production environment (been there, done that – once or twice...).

于 2013-03-24T09:57:01.600 回答
-1

您可以在插入之前使用 set utf8 to mysql 。它可以在数据库中插入特殊字符。仅供参考http://php.net/manual/en/function.mysql-set-charset.php

于 2013-03-24T09:22:35.017 回答