What is Smarty?
Why use it?
Use Cases and Work Flow
Syntax Comparison
Template Inheritance
Best Practices
Crash Course
You may use the Smarty logo according to the trademark notice.
For sponsorship, advertising, news or other inquiries, contact us at:
Table of Contents
有许多种文本数据的编码方式,ISO-8859-1 (Latin1) 和 UTF-8 是最常见的。
除非明确声明SMARTY_RESOURCE_CHAR_SET
使用的字符集,默认
Smarty当遇到多字节字符情况
会使用UTF-8
作为内置的字符集,
而当没有多字节字符情况下使用ISO-8859-1
。
ISO-8859-1
从开始就是PHP内置的默认字符集。
Unicode从1991年开始演变而来,而且逐渐替代了其他的字符集,因为其能对大多数已知的字符进行编码,
而且做到了跨各种不同字符集的系统(latin, cyrillic, japanese, …)。
UTF-8
是unicode中使用的最多的编码,它可以用最小的尺寸提供成千上万的字符。
现在unicode和UTF-8已经非常流行了,所以强烈建议使用它们。
从Smarty3.1开始,Smarty核心类和插件都被设计成兼容UTF-8的。 要做到良好的兼容性,最好开启多字节字符的PECL库。 除非PHP环境可以提供这个库,Smarty将不一定能完整兼容UTF-8。
Example 11.1. 设置字符集编码
// 使用日文字符集编码 if (function_exists('mb_internal_charset')) { mb_internal_charset('EUC-JP'); } define('SMARTY_RESOURCE_CHAR_SET', 'EUC-JP'); require_once 'libs/Smarty.class.php'; $smarty = new Smarty();