Php tutorial shtml generation class usage
<? Php
Class Shtml {
Var $ DataSource; // array
Var $ Templet; // string
Var $ FileName;
// Bind the data source
Function BindData ($ arr ){
$ This-> DataSource = $ arr;
}
Function Create (){
// Just talk about the idea and write it yourself:
$ Tmp = $ this-> Templet;
Foreach ($ this-> DataSource as $ key => $ value ){
// Replace the <FIELD _ $ key> string in the template string
$ Tmp = str_replace ('<FIELD _'. $ key. '>', $ value, $ tmp );
}
// Generate a file and save the disk.
$ Fp = fopen ($ this-> FileName, 'w ');
If (fwrite ($ fp, $ tmp )){
Fclose ($ fp );
} Else {
Fclose ($ fp );
}
}
}
// Usage:
/* $ Arr = array ();
$ Arr ["title"] = "here is the title ";
$ Arr ["content"] = "content here ";
$ Obj = new Shtml;
$ Obj-> FileName = "xxx.htm ";
$ Obj-> Templet = "title: <FIELD_title> content: <FIELD_content> ";
$ Obj-> BindData ($ arr );
// Everything is OK
$ Obj-> Create ();*/
?>