$value){ //html有効 $html=$value; $html = str_replace( '{', '{', $html); $html = str_replace( '}', '}', $html); $data = str_replace( '{{@'.$key.'}}', $html, $data); //html無効 $xss=htmlspecialchars($value,ENT_QUOTES,'UTF-8'); $xss = str_replace( '{', '{', $xss); $xss = str_replace( '}', '}', $xss); $data = str_replace( '{{'.$key.'}}', $xss, $data); } //未変換タグ除去 $data=preg_replace('/{{.*}}/','',$data); //変換されたデータを返す return $data; } // ---------- 関数終了---------- // テンプレート出力用の連想配列初期化 $temp_array=array(); // テンプレートファイルの読み込み $temp_data = file_get_contents('template.html'); // 適当に$output に配列名とデータを登録 $temp_array['title']='デモタイトル'; $temp_array['data']=date("Y/m/d H:i:s"); $temp_array['text']='Hello World!'; $temp_array['html']='Google'; //テンプレート関数実行 $output=template_engin($temp_data,$temp_array); echo $output;