| 148 |
lars |
1 |
Charset Encoding {#charset}
|
|
|
2 |
================
|
|
|
3 |
|
|
|
4 |
Charset Encoding {#charset.encoding}
|
|
|
5 |
================
|
|
|
6 |
|
|
|
7 |
There are a variety of encodings for textual data, ISO-8859-1 (Latin1)
|
|
|
8 |
and UTF-8 being the most popular. Unless you change `Smarty::$_CHARSET`,
|
|
|
9 |
Smarty recognizes `UTF-8` as the internal charset if
|
|
|
10 |
[Multibyte String](https://www.php.net/mbstring) is available,
|
|
|
11 |
`ISO-8859-1` if not.
|
|
|
12 |
|
|
|
13 |
> **Note**
|
|
|
14 |
>
|
|
|
15 |
> `ISO-8859-1` has been PHP\'s default internal charset since the
|
|
|
16 |
> beginning. Unicode has been evolving since 1991. Since then it has
|
|
|
17 |
> become the one charset to conquer them all, as it is capable of
|
|
|
18 |
> encoding most of the known characters even across different character
|
|
|
19 |
> systems (latin, cyrillic, japanese, ...). `UTF-8` is unicode\'s most
|
|
|
20 |
> used encoding, as it allows referencing the thousands of character
|
|
|
21 |
> with the smallest size overhead possible.
|
|
|
22 |
>
|
|
|
23 |
> Since unicode and UTF-8 are very wide spread nowadays, their use is
|
|
|
24 |
> strongly encouraged.
|
|
|
25 |
|
|
|
26 |
> **Note**
|
|
|
27 |
>
|
|
|
28 |
> Smarty\'s internals and core plugins are truly UTF-8 compatible since
|
|
|
29 |
> Smarty 3.1. To achieve unicode compatibility, the [Multibyte
|
|
|
30 |
> String](https://www.php.net/mbstring) PECL is required. Unless your PHP
|
|
|
31 |
> environment offers this package, Smarty will not be able to offer
|
|
|
32 |
> full-scale UTF-8 compatibility.
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
// use japanese character encoding
|
|
|
36 |
if (function_exists('mb_internal_charset')) {
|
|
|
37 |
mb_internal_charset('EUC-JP');
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
require_once 'libs/Smarty.class.php';
|
|
|
41 |
Smarty::$_CHARSET = 'EUC-JP';
|
|
|
42 |
$smarty = new Smarty();
|
|
|
43 |
|
|
|
44 |
|