0

这是我的萤火虫数据

action=saveOrder&name=Aprova%C3%A7%C3%A3o+dos

在服务器端,我试图将其保存到数据库中,名称列有排序规则 - utf8_general_ci

这是我的 php 脚本 1。

$name= htmlentities(str_replace("+", "", rawurldecode($_POST["name"])));

我也试过2。

$name= html_entity_decode(str_replace("+", "", rawurldecode($_POST["name"])));

如果您看到此链接 http://writecodeonline.com/php/ 2. 在那里工作,但是当我将它保存在数据库中时,它没有与最后一个代码正确保存,保存的值是 Aprovação dos和案例 1. 它保存了这个 Aprovação dos

应该保存在数据库中的值是 Aprovação dos

函数保存订单()
{
  变量参数={};
  params.action='saveOrder';
  params.name=$("#cliente_nome").val();
  $.post('saveorders.php',参数,函数(数据)
  {
    警报(数据);
  });
}

PHP 代码

 <?php

  mb_internal_encoding("UTF-8");
  include_once("clase.php");//数据库连接文件
  session_start();
  $name=html_entity_decode(str_replace("+", "", rawurldecode($_POST["name"])));
  Policy::saveOrders($name);

  ?>

任何帮助表示赞赏

4

3 回答 3

1

在您的网站和数据库之间创建链接时,请将其设置为 UTF-8。此外,使用 ANSI 将您的 PHP 页面保存为 UTF-8(没有 BOM 的 UTF-8 编码)。确保您的数据库和表也使用 UTF-8 编码。将php的内部编码设置为UTF-8。

于 2012-05-29T20:48:37.567 回答
0

Make sure that the file encoding (the .php file itself) is UTF-8.

Also, add header('Content-Type:text/html; charset=UTF-8'); to your UTF-8 pages and see if it helps.

于 2012-05-29T21:21:48.223 回答
0

Here are the steps I took to resolve this

  1. Set the collation of database table to utf8_general_ci
  2. The PHP Page which is receiving the data, set its header to mb_internal_encoding("UTF-8"); and iconv_set_encoding("internal_encoding", "UTF-8"); [This one I took from the above answers, I am not sure which one to keep and which one to remove, I kept both as it worked for me] 3.while sending data using jquery use escape, so this becomes
     params.name=$("#cliente_nome").val(); 
    this
      params.name=escape($("#cliente_nome").val()); 
  3. The server page should use rawurlencode method e.g
 <?php

  mb_internal_encoding("UTF-8");
  iconv_set_encoding("internal_encoding", "UTF-8");
  include_once ("clase.php");// Database connection file
  session_start();
  $name=str_replace("+", " ", rawurldecode($_POST["name"]));
  Policy::saveOrders($name);

  ?>
于 2012-05-30T04:47:23.547 回答