My specific implementation example
In order to help everyone have a perceptual understanding, here I give the file-based processing method implemented on my homepage. Only the main processing code, incomplete.
$#@60;?
1 $tmpfile="../tmp/".basename($REQUEST_URI);
2 $tmpfile=str_replace("?", "_", $tmpfile) ;
3 $tmpfile=str_replace("&", "_", $tmpfile);
4 if(file_exists($tmpfile))
5 {
6 $cflag=false;
7 $dtmp=filemtime($tmpfile);
8 $itmp=filemtime($incfile);
9 $cflag=$cflag | ($dtmp $#@60; $itmp);
10 $ctmp=filemtime(basename($PHP_SELF));
11 $cflag=$cflag | ($dtmp $#@60; $ctmp);
12 $ttmp=filemtime("template/content.ihtml" );
13 $cflag=$cflag | ($dtmp $#@60; $ttmp);
14 }
15 else
16 $cflag=true;
17
18 if(!$cflag) //Use existing file
19 {
20 readfile($tmpfile);
21 exit;
22 }
23
24 //Create New file
25 include "template.class.php3";
26
27 $fp=fopen($incfile, "r");
28 $content=fread($fp, filesize ($incfile));
29 fclose($fp);
30
31 //Template processing is done below
32 $t = new Template("template", "keep" );
33
34 $t-$#@62;set_file("contentfile","content.ihtml");
35
36 $t-$#@62;set_var(
37 array(
38 "content"=$#@62;$content
39 ));
40
41 $t-$#@62;parse("outputcontent"," contentfile");
42
43 $fp=fopen($tmpfile, "w");
44 if($fp)
45 {
46 flock($fp, 3) ;
47 fwrite($fp, $t-$#@62;get_var("outputcontent"));
48 flock($fp, 1);
49 fclose($fp);
50 }
51 $t-$#@62;p("outputcontent");
?$#@62;
Let me first introduce to you my directory structure:
/-- -bin/ Execution program directory
| |--content.php3 Program used to process file display
| |--template/ Directory used to store template files
| |---content.ihtml Template file
|-docs/ Data file
|-tmp/ Storage buffer file
http://www.bkjia.com/PHPjc/531740.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531740.htmlTechArticleMy specific implementation example. In order to help everyone have a perceptual understanding, here I give the implementation on my homepage based on file processing. Only the main processing code, incomplete. ...