PHP article content is paged and the corresponding HTM static page code is generated

  • 2020-03-31 20:54:56
  • OfStack

 
<?php 
$url='test.php?1=1'; 
$contents="fjka;fjsa;#page# Batch generation split file and add paging code "; 
$ptext ='#page#'; 
ContentsPages($url,$contents,$ptext) 
 
//The article array
$arr = explode($ptext,$contents); 
//Array length & total number of pages
$total = count($arr); 
//The current page
$nowpage = $_GET['pages']?$_GET['pages']:1; 
//On the page
$prepage = $nowpage==1?1:$nowpage-1; 
//On the next page
$nextpage = $nowpage>$total-1?$total:$nowpage+1; 
//The last page
$lastpage = $total; 
$pdiv = '<br /><div style="height:30px;width:500px;border:1px; blackground-color:#ff0000;">'; 
$pdiv .= " The first {$nowpage} page  /  The total {$total} page   "; 
//Home page link
$pdiv .= "<li style="display:inline;"><a href="{$url}&pages=1" style="text-decoration:none;"> Home page </a></li>"; 
//On page links
$pdiv .= "<li style="display:inline;"><a href="{$url}&pages={$prepage}" style="text-decoration:none;">   The previous page   </a></li>"; 
//Display a pagination list
$color = ''; 
for($i = 1; $i<=$total; $i++) 
{ 
if($i == $nowpage) 
{ 
$color= "color:#ff0000;"; 
} 
else 
{ 
$color = ''; 
} 
$pdiv .= "  <li style="display:inline;"><a href="{$url}&pages={$i}" style="text-decoration:none;"><span style="{$color}">{$i}</span></a></li>"; 
} 
//On the next page link
$pdiv .= "  <li style="display:inline;"><a href="{$url}&pages={$nextpage}" style="text-decoration:none;">   The next page </a></li>"; 
//At the end of the page links
$pdiv .= "<li style="display:inline;"><a href="{$url}&pages={$lastpage}" style="text-decoration:none;">   At the end of the page   </a></li>"; 
$pdiv .= '</div>'; 
//output
echo $arr[$nowpage-1]; 
// No pagination Display a pagination list
if( $total <=1) $pdiv = ''; 
//Output paging list
echo $pdiv; 
?> 

The following is the relevant statically generated page, although the code is incorrect but the idea is ok.

<? 
$tmpBody = "fjka;fjsa;{page} Batch generation split file and add paging code "; 
$tmpUrl = 'www.jb51.net'; 
$tmpUrlarray = explode('.',$tmpUrl); 
$tmpArray = explode('{page}',$tmpBody); 
$total = count($tmpArray); 
$id="2"; 
if( $total >1 ) 
{ 
$tmpStr = ''; 
for( $i=0;$i<$total;$i++ ) //Iterate through all the pages
{ 
if( $i==0 ) 
{ 
$str .='<a href='.$id.'.htm class=bodypage target=_self>'.($i+1).'</a> '; 
} 
else 
{ 
$str .='<a href='.$id.'_'.$i.'.htm class=bodypage target=_self>'.($i+1).'</a> '; 
} 
} 
//Batch generation split file and add paging code
$str = '<div class=mupage>'.$str.'</div>'; 
for( $j=0;$j<$total;$j++ ) 
{ 
if( $j==0 ) 
{ 
$fname =$id.'.htm'; 
} 
else 
{ 
$fname =$id.'_'.$j.'.htm'; 
} 
$tempMu = str_replace('{htmlContent}',$tmpArray[$j].$str,$tempLate); 
makeHtml($tempMu,$filePath,$fname); //This function is not clear, a file creation code
} 
$mupage =1; 
} 
$tempLate = str_replace('{htmlContent}',$tmpBody,$tempLate); //Ordinary articles are paged out with {page} to save to an array of recycled component page address, and then from the exploded array of the contents of the generated HTM page
$total=0; 
$str=''; 
$i=0; 
$j=0; 
 
function makeHtml($tempMu,$filePath,$fname){ 
$fp = fopen($filePath.$filename, "w"); 
fwrite($fp, $tempMu); 
fclose($fp); 
} 
?>


Related articles: