■shift-jisで吐き出したい場合。※携帯の時とかね。
function SJIS_Encoding($tpl_output, &$smarty){
$tpl_output = mb_convert_encoding($tpl_output,’SJIS’,’EUC-JP’);
return $tpl_output;
}
#呼び出し方:EUCからSJISへ変換出力
$smarty->register_outputfilter(“SJIS_Encoding”);
↑ここまではcommon.phpなどに書いてしまえばOK
header(“Content-type: application/xhtml+xml”);
$smarty->clear_cache(MENUTPL);
$smarty->assign(“USERNAME”,$_SESSION[‘USERNAME’]);
$smarty->assign(“URL_BASE”,URL_BASE);
$smarty->display(MENUTPL);#テンプレート表示
さらにPHPをEUCで書き、テンプレートhtmlもEUCで保存、だけど<meta http-equiv=”Content-Type” content=”text/html; charset=shift_jis” />とする
さらに違う書き方も発見した。
引用元
http://php.atseason.com/?eid=456957
<?php
function smarty_prefilter_sjis2euc($buff,&$smarty)
{
return mb_convert_encoding($buff,’EUC-JP’,’SJIS’);
}
?>
これを以下のように呼び出す。
$smarty->load_filter(‘pre’,’sjis2euc’);