charset = UTF-8 □技術メモ - php ※管理人の個人的な技術メモです。このページの内容を実行した結果について 管理人はいかなる責任も負いかねますのでご自身の責任でお試しください。 ----------------------------------------------------------- ○環境構築(PHP4) ・以下をdownloadしてインストール prdownloads.sourceforge.net/phpdev5/phpdev423.exe ・2K-NT-XP-phpdev_start と www のショートカットをdesktopに作成 ・2K-NT-XP-phpdev_start でwebサービス開始。ルートディレクトリは WWW ・http://localhost/ で www の内容を表示。 ○環境構築(PHP5) ・以下のxamppをdownloadしてインストールする(WinXPの場合) xampp-win32-1.8.2-6-vc9-installer.exe (1.8.2版を選択した場合) ・xamppコントロールパネルが開く→ 各コンポーネントが正しくインストールされたことを確認する → Apacheをstart → http://localhost → 日本語を選択 → phpinfo() → PHP5に関する情報が表示される。 ・ルートディレクトリは C:/xampp/htdocs ・http://localhost/index.html → It works! と表示されること。 ○デバッグログ出力(PHP4) ○Smarty 環境設定および実行方法 ・主にPHPで使用されるテンプレートエンジン。多くのスレームワークで テンプレートとして使用されている。 ・以下からDownLoad, 展開する。 www.smarty.net → DownLoad → Smarty-3(もしくは2).x.x.zip → Libsのパスが C:\Smarty\Libs になるようにフォルダ名変更および移動 ・\php\php.iniを編集する - (1) include_pathに 上記のC:\Smarty\Libsを追加 extension = php_mbstring.dll //日本語使用設定, コメント ; を外す ・\php\php.iniを編集する - (2) [mbstring]内を以下のように設定 mbstring.language=Japanese mbstring.internal_encoding=UTF-8 //デフォルトはEUC-JP mbstring.http-input=pass mbstring.http-output=pass mbstring.encoding-translation=OFF mbstring.detect-order=UTF-8,SJIS,EUC-JP,JIS,ASCII //文字コード判定の優先順位 mbstring.substitute_character=none mbstring.func_overload=0 mbstring.strict_detection=off //文字コードの厳密な判定 ;mbstring.http_output_conv_mimetype= //とりあえずコメント ----以下、プロジェクト構築手順 ・C:\smartyTemplete\stest を作成。直下に以下の4つのフォルダ(名称は固定)を作成する。 \cache //最終的なHTMLのキャッシュ(Smartyが使用する) \configs //設定ファイルを配置 \templates //作成したテンプレートを配置 \templates_c //コンパイルしたテンプレート(Smartyが使用する) ・テンプレートの作成 上記の\templatesに配置する sample.tpl -------- //utf-8を指定 smarty sample

{$msg1}

{$msg2}

-------- ・PHPのルートフォルダ(PHP5ならhtdocs)下に \smarty\stest を作成して、 以下のPHPを配置する。 sample.php -------- cache_dir ='C:/smartyTemplate/stest/cache/'; $smarty->config_dir ='C:/smartyTemplate/stest/configs/'; $smarty->template_dir='C:/smartyTemplate/stest/templates/'; $smarty->compile_dir ='C:/smartyTemplate/stest/templates_c/'; $smarty->assign('msg1','unicodeのテスト'); $smarty->assign('msg2','齋籐 松濤 祷 禱'); //shift-jisにすると禱が?表示になる $smarty->display('sample.tpl'); ?> ・apacheを起動して以下のアドレスにアクセス localhost/smarty/stest/sample.php -----------------------------------------------------------