Home > Article > Backend Development > PHP combined with smarty generates static pages and paging code in PHP articles
This article introduces the method of using smarty template engine to generate static pages in PHP, as well as the implementation code of article paging in PHP. Friends who need it can refer to it.
Example, smarty in php generates static pages and pagination codes in articles. Topic: PHP paging code principle <?php include "../config.php"; checkLogin (); if (isset ($_GET['act']) && $_GET['act'] == 'add') { // var_dump ($_POST); $title = isset ($_POST['title']) ? trim ($_POST['title']) : ''; $tag = isset ($_POST['tag']) ? trim ($_POST['tag']) : ''; $content = isset ($_POST['content']) ? $_POST['content'] : ''; $create_time = time (); echo $sql = "INSERT INTO `article` (`title`,`tag`,`content`,`create_time`) VALUES ('{$title}','{$tag}','{$content}','{$create_time}')"; $_POST['create_time'] = $create_time ; $res=mysql_query ($sql); $article_id = mysql_insert_id(); $file_name = '../html/'.$article_id.'.html'; if ($res) { $temp = explode ('<div style=\"page-break-after: always;\"><span style=\"display: none;\"> </span></div>',$content); $num = 0; foreach ($temp as $key => $val ) { $num++; $pagenav = ''; if ($key == 0) { $file_name = '../html/'.$article_id.'.html'; } else { $file_name = '../html/'.$article_id.'_'.($key+1).'.html'; } for ($i=1;$i<=count($temp);$i++) { if (($key+1) == $i) { $pagenav .= " <b>{$i}</b> "; } else { if ($i == 1) { $pagenav = $pagenav." {$i} "; } else { $pagenav .= " {$i} "; } } } $_POST['content'] = $val ; $tpl->assign ('a',$_POST); $tpl->assign ('pagenav',$pagenav); $html = $tpl->fetch('show_article.html'); $fp=fopen ($file_name,'w'); if ($fp) { fwrite ($fp,$html); fclose ($fp); } } alert ("生成{$num}篇成功",'add_article.php'); } else { alert ('增加失败!'); } } else { //$FCK->Value='fanglor is a boy !'; $editer = $FCK->CreateHtml(); $tpl->assign ('editer',$editer); $tpl->display ('add_article.html'); } ?> Related articles for generating static pages:
Article paginationRelated articles:
|