The php article content is paginated and the corresponding htm static file instance code is generated. Generally, the main user is paging long files.
The php article content is paginated and the corresponding htm static file instance code is generated. Generally, the main user is paging long files.
The Code is as follows:
$ 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;
$ Pp ='
';
$ Pp. = "Page {$ nowpage}/total page {$ total ";
// Home Page
$ Pp. ="
Homepage";
// Link to the previous page
$ Pp. ="
Previous Page";
// Display the page list
$ Color = '';
For ($ I = 1; $ I <= $ total; $ I ++)
{
If ($ I = $ nowpage)
{
$ Color = "color: # ff0000 ;";
}
Else
{
$ Color = '';
}
$ Pp. ="
{$ I}";
}
// Link to the next page
$ Pp. ="
Next Page";
// Last link
$ Pp. ="
Last page";
$ Pp. ='
';
// Output content
Echo $ arr [$ nowpage-1];
// If no page is displayed, the page list is not displayed.
If ($ total <= 1) $ pp = '';
// Output pagination list
Echo $ pp;
?>
The following is the related static generation page. Although the code is incorrect, the idea is correct.
The 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. = ''. ($ I + 1 ).'';
}
Else
{
$ Str. = ''. ($ I + 1 ).'';
}
}
// Generate files in batches and add paging code
$ Str ='
'. $ Str .'
';
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 );
}
?>