例子,php中smarty生成静态页、文章内分页代码。专题:php分页代码原理
<?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." <a href='{$article_id}.html'>{$i}</a> "; } else { $pagenav .= " <a href='{$article_id}_{$i}.html'>{$i}</a> "; } } } $_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'); } ?>
生成静态页面的相关文章:
文章分页的相关文章: