【问题标题】:PHP: Make Site Unicode CompatiblePHP:使网站 Unicode 兼容
【发布时间】:2009-12-02 06:01:12
【问题描述】:

如何使我的网站兼容 unicode 以支持英语以外的更多语言。

谢谢

【问题讨论】:

  • 您只需要使用 Unicode 字符编码。就是这样。
  • 仅供参考,我不会多次问同一个问题。

标签: php language-agnostic unicode utf-8


【解决方案1】:

对于 PHP:

首先,您需要将脚本编码设置为 utf8(Eclipse/Notepass++ 或 Ultraedit 等 IDE/编辑器能够做到这一点)。如果你会输出 xhtml,那么你可以添加:

<?xml version="1.0" encoding="utf-8"?>
<html>
    <head>
        <meta http-equiv="content-type" content="application/xhtml+xml;charset=utf-8" />
    </head>

强制浏览器使用utf8。

如果您正在使用例如 xml 文档、数据库(其中许多支持 utf8)或任何其他不是 utf8 的来源,请查看 php 文档中的以下转换函数:

string utf8_encode  ( string $data  );
string utf8_decode  ( string $data  );

string iconv  ( string $in_charset  , string $out_charset  , string $str  );

这里是文档的链接:

http://www.php.net/manual/en/function.utf8-decode.php

http://www.php.net/manual/en/function.utf8-encode.php

http://www.php.net/manual/en/book.iconv.php

作为补充尝试:

http://de.php.net/manual/en/book.mbstring.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-29
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多