从php到mysql的特殊字符

发布于 2024-12-16 12:24:12 字数 664 浏览 3 评论 0原文

我知道有很多几乎相同的问题,但我仍然没有找到我的问题的答案。 我想将“les Îles Açores”放入数据库中。但我得到:

les Îles Açores

我尝试使用:

  • SET Names 'ut8)
  • $mysqli->set_charset("utf8");
  • mysql_real_escape_string()
  • < code>htmlentities (这里我得到了 htmlentities,但我想知道是否还有其他方法)

Code:

$name_fr = $_POST["name_fr"]; $name_nl = $_POST["name_nl"];
$arr_kollommen = array("NAME_FR","NAME_NL");
        $arr_waardes = array($naam_nl,$naam_fr);
        $obj_db->insert("landen",$arr_kollommen,$arr_waardes);

有人知道如何解决我的小问题吗? 非常感谢!

I know there have been a lot of almost the same questions, but I still didn't find the answer to my problem.
I want to place "les Îles Açores" into the db. But I get:

les Îles Açores

I tried usin:

  • SET Names 'ut8)
  • $mysqli->set_charset("utf8");
  • mysql_real_escape_string()
  • htmlentities (Here I got htmlentities, but I want to know if there's another way)

Code:

$name_fr = $_POST["name_fr"]; $name_nl = $_POST["name_nl"];
$arr_kollommen = array("NAME_FR","NAME_NL");
        $arr_waardes = array($naam_nl,$naam_fr);
        $obj_db->insert("landen",$arr_kollommen,$arr_waardes);

Does someone has an idea how to solve my litle problem?
Thank you very much!

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

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

发布评论

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

评论(5

弱骨蛰伏 2024-12-23 12:24:12

确保表使用正确的 CHARSET,例如:

CREATE TABLE myTable (
    one VARCHAR(255),
    two VARCHAR(255)
) DEFAULT CHARSET=utf8;

Make sure the table uses the correct CHARSET, for example:

CREATE TABLE myTable (
    one VARCHAR(255),
    two VARCHAR(255)
) DEFAULT CHARSET=utf8;
  1. 确保您实际上使用 UTF8 编写(这意味着您编写代码的 IDE/编辑器必须将编码设置为 UTF8)。
  2. 获取记录后,数据库和页面上的记录是否都已损坏,还是仅在数据库中?
  1. Make sure you actually write in UTF8 (meaning your IDE / editor you write your code must have encoding set to UTF8).
  2. Is the record corrupted both in the DB and on your page after you fetch it or only in DB?
风尘浪孓 2024-12-23 12:24:12
$name_fr = $_POST["name_fr"]; 
$name_nl = $_POST["name_nl"];
$arr_kollommen = array("NAME_FR","NAME_NL");
$arr_waardes = array($naam_nl,$naam_fr);
$obj_db->insert("landen",$arr_kollommen,$arr_waardes);

尝试使用而不是编码到 utf_8 解码。
像这样:

$name_fr = $_POST["name_fr"]; 
$name_nl = $_POST["name_nl"];
$naam_fr = utf8_decode($naam_fr);
$naam_nl = utf8_decode($naam_nl);
$arr_kollommen = array("NAME_FR","NAME_NL");
$arr_waardes = array($naam_nl,$naam_fr);
$obj_db->insert("landen",$arr_kollommen,$arr_waardes);
$name_fr = $_POST["name_fr"]; 
$name_nl = $_POST["name_nl"];
$arr_kollommen = array("NAME_FR","NAME_NL");
$arr_waardes = array($naam_nl,$naam_fr);
$obj_db->insert("landen",$arr_kollommen,$arr_waardes);

Try using instead of encode to utf_8 decode.
like this:

$name_fr = $_POST["name_fr"]; 
$name_nl = $_POST["name_nl"];
$naam_fr = utf8_decode($naam_fr);
$naam_nl = utf8_decode($naam_nl);
$arr_kollommen = array("NAME_FR","NAME_NL");
$arr_waardes = array($naam_nl,$naam_fr);
$obj_db->insert("landen",$arr_kollommen,$arr_waardes);
痞味浪人 2024-12-23 12:24:12

我可以看到 2 个可能的原因:

1)您的数据库不具有 UTF-8 字段

2)当您从服务器读取数据时,您没有将连接设置为 utf-8。如果您在写入时必须将其设置为utf-8,那么在读取时也必须将其设置为utf-8。

使用 PHPMyAdmin 检查数据是否被破坏...如果是,则意味着您的 SET 名称“utf-8”不起作用...

2 possible reasons i can see:

1) Your database doesn't feature UTF-8 fields

2) When you read your data from the server, you are not setting the connection as utf-8. If you have to set it utf-8 when writting you also have to set it utf-8 when reading.

Check using PHPMyAdmin if the data is wrecked... If it is, then it means that your SET names'utf-8' is not working...

旧瑾黎汐 2024-12-23 12:24:12

您是否将“UTF-8”参数传递到您的 htmlentities 中,并以这种方式进行 html_entity_decode ?

html_entity_decode($text,ENT_QUOTES,"UTF-8");

Do you pass the "UTF-8" parameter into your htmlentities, and html_entity_decode this way ?

html_entity_decode($text,ENT_QUOTES , "UTF-8");

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