Sie sind auf Seite 1von 2

Membuat template di PHP 1. Variable-variable yang terdapat pada index.php $main $content $fd $filename $template $action 2.

ion 2. Fungsi dan command yang terdapat pada index.php function template(); function home(); fopen fclose global stripslashes eregi_replace echo switch default: break: cat: variable $main disimbolkan dengan <%main%> Langkah-langlah pembuatan template: 1. Membuat file theme.htm

<html> <body> <table cellpadding ="0" spacepadding="0" border="0"> <tr><td valign=top align=left> % main % </td></tr> </table> </body> </html>

2. Membuat file index.php


<?php function template($content) { global $main; $filename = "theme.htm"; if(!fd=fopen($filename, "r")) { $error = 1; } else { $template = fread($fd, filesize($filename)); fclose($fd); $template = stripslashes($template); $template = eregi_replace("<% main %>", "$main", "$template");

$template = eregi_replace("<% content %>", "$content", $template); echo "$template"; } } function home() { global $main; include ("test.php"); template("$data"); } switch($action) { default: home(); break; } ?> 3. Membuat File test.php untuk ujicoba <?php $main.="Ini adalah uji coba membuat template HTML.<br /> Ini hanyalah uji coba"; ?> 4. Tes menggunakan browser

Das könnte Ihnen auch gefallen