【问题标题】:How to solve UTF-8/Unicode problems in PHP and MySQL [closed]如何解决 PHP 和 MySQL 中的 UTF-8/Unicode 问题 [关闭]
【发布时间】:2012-07-15 01:01:06
【问题描述】:

我需要一个在 UTF8 Unicode 系统上运行良好的简单 PHP 和 MySQL 源代码。请给我一个 100% 在 UTF8 Unicode 上工作的最简单的源代码。

【问题讨论】:

  • 认为您可以通过相当简单的 Google 搜索获得该信息

标签: php mysql unicode encoding utf-8


【解决方案1】:

告诉mysql和php你使用utf-8:

<?php
   mb_internal_encoding("UTF-8");

   $db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password');
?>

【讨论】:

  • 好的。我会尽力。我将我的数据库设置为 UTF8 和 UTF8_Unicode_ci
  • 它将正确的字符插入到数据库中,但在浏览器中显示如下:“КомменС,РёСЂРѕРІР°С,СЊ...”(西里尔文)
  • 然后告诉浏览器使用utf-8到:header ('Content-type: text/html; charset=utf-8');
  • .....
猜你喜欢
  • 2014-08-21
  • 2018-06-17
  • 1970-01-01
  • 2011-06-05
  • 2010-12-26
  • 2015-04-29
  • 2012-04-11
  • 2021-09-26
  • 1970-01-01
相关资源
最近更新 更多