Smartyを携帯向けに

Smartyを携帯に対応させようとすると、どうしてもSJISの問題が発生する。
「{」「}」がSJISのコードに含まれるため、テンプレートはSJISでは書けない。
そこで、Smartyのoutputfilterを使用した。

1
2
3
4
5
6
7
8
9
10
11
12
<?php
//
// 画面出力時に、テンプレートをUTF-8からSJISに変換する。
//
function filterUTF8ToSJIS($buff, &$smarty) {
    return mb_convert_encoding($buff,"SJIS","UTF-8");
}
 
$smarty= new Smarty();                              //Smartyオブジェクト生成
$smarty->register_outputfilter("filterUTF8ToSJIS"); //フィルターの登録
ini_set("default_charset", "Shift_JIS");            //PHPの設定default_charsetにSJISを設定
?>

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">