Copy codeThe Code is as follows:
<? Php
$ Url = 'test. php? 1 = 1 ';
$ Contents = "fjka; fjsa; # page # generate files in batches and add paging code ";
$ Ptext = '# page #';
ContentsPages ($ url, $ contents, $ ptext)
/**
* Function name: ContentsPages
* Function: pagination of article content
* Parameter: $ url document content page URL type string, $ contents document content page content type string, $ ptext paging identifier type string
* Author: seven nights
* QQ: 64438136 linus.php@gmail.com MSN: zhijian@live.com
*/
// Document Array
$ Arr = explode ($ ptext, $ contents );
// Array length & total number of pages
$ Total = count ($ arr );
// Current page
$ Nowpage = $ _ GET ['pages ']? $ _ GET ['page']: 1;
// Previous Page
$ Prepage = $ nowpage = 1? 1: $ nowpage-1;
// Next page
$ Nextpage = $ nowpage> $ total-1? $ Total: $ nowpage + 1;
// Last page
$ Lastpage = $ total;
$ Pdiv = '<br/> <div style = \ "height: 30px; width: 500px; border: 1px; blackground-color: # ff0000; \"> ';
$ Pdiv. = "Page {$ nowpage}/total page {$ total ";
// Home Page
$ Pdiv. = "<li style = \" display: inline; \ "> <a href = \" {$ url} & pages = 1 \ "style = \" text-decoration: none; \ "> homepage </a> </li> ";
// Link to the previous page
$ Pdiv. = "<li style = \" display: inline; \ "> <a href = \" {$ url} & pages = {$ prepage} \ "style = \" text-decoration: none; \ "> previous page </a> </li> ";
// Display the page 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> ";
}
// Link to the next page
$ Pdiv. = "<li style = \" display: inline; \ "> <a href = \" {$ url} & pages = {$ nextpage} \ "style = \" text-decoration: none; \ "> next page </a> </li> ";
// Last link
$ Pdiv. = "<li style = \" display: inline; \ "> <a href = \" {$ url} & pages = {$ lastpage} \ "style = \" text-decoration: none; \ "> last page </a> </li> ";
$ Pdiv. = '</div> ';
// Output content
Echo $ arr [$ nowpage-1];
// If no page is displayed, the page list is not displayed.
If ($ total <= 1) $ pdiv = '';
// Output pagination list
Echo $ pdiv;
?>
The following is the related static generation page. Although the code is incorrect, the idea is correct.
Copy codeThe Code is as follows:
<?
$ TmpBody = "fjka; fjsa; {page}: generate multiple files 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 ++) // traverses all pages
{
If ($ I = 0)
{
$ Str. = '<a href0000'.0000id.'.htm class = bodypage target = _ self>'. ($ I + 1). '</a> ';
}
Else
{
$ Str. = '<a href0000'.0000id.'_'.0000i.'.htm class = bodypage target = _ self>'. ($ I + 1). '</a> ';
}
}
// Generate files in batches and add paging code
$ Str = '<div class = mupage>'. $ str. '</div> ';
For ($ j = 0; $ j <$ total; $ j ++)
{
If ($ j = 0)
{
$ Fname your id.'.htm ';
}
Else
{
$ Fname your id.'_'.w.j.'.htm ';
}
$ TempMu = str_replace ('{htmlContent}', $ tmpArray [$ j]. $ str, $ tempLate );
MakeHtml ($ tempMu, $ filePath, $ fname); // The code for creating a file is not described in this function.
}
$ Mupage = 1;
}
$ TempLate = str_replace ('{htmlContent}', $ tmpBody, $ tempLate); // common articles are retrieved by {page} and saved to an array to generate a paging address, then the htm page is generated based on the content of the explode array.
$ Total = 0;
$ Str = '';
$ I = 0;
$ J = 0;
/*
The origin of the Code is the id_page number, such as 100_1.htm,100_2.htm.
*/
Function makeHtml ($ tempMu, $ filePath, $ fname ){
$ Fp = fopen ($ filePath. $ filename, "w ");
Fwrite ($ fp, $ tempMu );
Fclose ($ fp );
}
?>