It only lets you modify a portion of the page, and of course this "part" is for you to determine. The artist first make a page, and then we use this page as a template (note that this template is not necessary to use EditRegion3 such code, this code is dreamwerver to facilitate their own design and identification), Replace the one we need to change in this template with a character that can be distinguished by HTML, such as "{title}" and "[title]". You only need to replace the data with these strings when generating static pages. That's what the template means.
Create a new PHP page and an HTML page [Template page]; Note: If you are invoking data from a database, save the data as an array, and then loop through the generation;
On the PHP page, open the HTML page and read the contents of the HTML page, replace parameters, new (open) a new HTML page, write the replaced content to a new file, close new file, and build successfully;
$open=fopen("Template.htm", "R");//Open Template file$content=fread($open,filesize("template.htm"));//Read template file Contents//print_r ($content);$content=Str_replace("{title}", "Test title",$content);//Replace$content=Str_replace("{contents}", "Test content",$content);$newtemp=fopen("1.htm", "w");//to open a nonexistent (new) page by writingfwrite($newtemp,$content);//Write the content you just replaced into a new filefclose($newtemp);Echo"Generate";
PHP Batch generated HTML test:
//Suppose the data transferred from the database is stored in a two-dimensional array $arr$arr=Array(Array("News title One", "news content One"),Array("News Title II", "News Content II")); foreach($arr as $key=$value){ $title=$value[0]; $contents=$value[1]; //Echo $title. $contents. '; $path=$key.‘. html; $open=fopen("Template.htm", "R");//Open Template file $handle=fread($open,filesize("template.htm"));//Read template file contents $content=Str_replace("{title}",$title,$handle);//Replace $content=Str_replace("{contents}",$contents,$handle); $newtemp=fopen($path, "W");//to open a nonexistent (new) page in write mode fwrite($newtemp,$content);//Write the content you just replaced into a new file fclose($newtemp); EchoGenerated;}
Paging problem:
If we specify paging, 20 articles per page. A sub-channel list of the article through the database query for 45, then, we first through the query to obtain the following parameters: 1, the total number of pages, 2, per page. The second step, for ($i = 0; $i < allpages; $i + +), page element acquisition, analysis, article generation, are executed in this loop. The difference is that die ("Create file". $filename. " Success! This sentence is removed and placed on the display after the loop, because the statement aborts the execution of the program. Cases:
$fp=fopen("Temp.html", "R");$content=fread($fp,filesize("Temp.html"));$onepage= ' 20';$sql= "SELECT id from article where channel= '$channelid’";$query=mysql_query($sql);$num=mysql_num_rows($query);$allpages=Ceil($num/$onepage); for($i= 0;$i<$allpages;$i++){ if($i= = 0){ $indexpath= "Index.html"; } Else { $indexpath= "Index_".$i." html; } $start=$i*$onepage; $list="; $sql _for_page= "Select Name,filename,title from article where channel= '$channelid' Limit$start,$onepage"; $query _for_page=mysql_query($sql _for_page); while($result=$query _for_page){ $list. = ' <a href= '.$root.$result[' filename ']. ' Target=_blank> '.$title.’ </a><br>'; } $content=Str_replace("{articletable}",$list,$content); if(Is_file($indexpath)){ @unlink($indexpath);//if the file already exists, delete the } $handle=fopen($indexpath, "W");//Open file pointer, create file if(!is_writable($indexpath)){ Echo"File:".$indexpath." Not writable, please check its properties and try again! ";//Modify to Echo } if(!fwrite($handle,$content)){//writing information to a file Echo"Generate Files".$indexpath." Failed! ";//Modify to Echo } fclose($handle);//Close Pointer}fclose($fp); die("Raw content page file completed, such as build incomplete, please check the file permissions system after regeneration!") ");
HTML template Generation static page and template paging processing