<p>kim_about数据库与生成html代码<br />
<img src="/up_pic/201602/seocninfo20100505185855.jpg" /><br />
单个页面显示添加修改删除信息简洁思路<br />
$action=$_GET["action"];<br />
switch ($action)<br />
{<br />
case "saveform":<br />
saveform();<br />
break;<br />
case "addform":<br />
addform($action);<br />
break;<br />
case "modify":<br />
addform($action);<br />
break;<br />
case "del":<br />
$about_id=intval($_GET["about_id"]);<br />
$db->query("delete from ve123_about where about_id=".$about_id."");<br />
break;<br />
}<br />
<br />
intval<br />
(PHP 3, PHP 4, PHP 5)<br />
intval -- 获取变量的整数值<br />
描述<br />
int intval ( mixed var [, int base] )<br />
通过使用特定的进制转换(默认是十进制),返回变量 var 的 integer 数值。<br />
var 可以是任何标量类型。intval() 不能用于 array 或 object。<br />
注: 除非 var 参数是字符串,否则 intval() 的 base 参数不会有效果。<br />
<br />
代码<br />
<!--?php<br /--> function saveform()<br />
{<br />
global $db,$config;<br />
$title=addslashes(replacebadchar(trim($_POST["title"])));<br />
$content=trim($_POST["content"]);<br />
$filename=replacebadchar(trim($_POST["filename"]));<br />
$url=replacebadchar(trim($_POST["url"]));<br />
$sortid=intval($_POST["sortid"]);<br />
$about_id=intval($_POST["about_id"]);<br />
$do_action=replacebadchar($_POST["do_action"]);<br />
$is_show=$_POST["is_show"];<br />
ob_start();<br />
require "../include/temp/a.php";<br />
$str=ob_get_contents();<br />
ob_end_clean();<br />
$str=stripslashes($str);<br />
file_put_contents("../a/".$filename.".html", $str);<br />
if ($do_action=="modify")<br />
{<br />
$array=array<br />
<br />
(title=>$title,content=>$content,url=>$url,filename=>$filename,sortid=>$sortid,<br />
<br />
is_show=>$is_show);<br />
$db->update("ve123_about",$array,"about_id=$about_id");<br />
jsalert("修改成功");<br />
}<br />
else<br />
{<br />
$array=array<br />
<br />
(title=>$title,content=>$content,url=>$url,filename=>$filename,sortid=>$sortid,<br />
<br />
is_show=>$is_show);<br />
$db->insert("ve123_about",$array);<br />
jsalert("提交成功");<br />
}<br />
}<br />
?><br />
<br />
相关函数<br />
function replacebadchar($str)<br />
{<br />
//return htmlspecialchars($str);<br />
//return $str;<br />
$farr = array(<br />
"/s+/",<br />
<br />
//过滤多余的空白<br />
"/<(/?)(scrīpt|i?frame|style|html|body|title|link|meta|?|%)([^>]*?)>/isU", //过<br />
<br />
滤 <scrīpt br=""><br />
<object的过滤<br> "/(<[^>]*)on[a-zA-Z]+s*=([^>]*>)/isU", //过<br />
<br />
滤javascrīpt的on事件<br />
<br />
);<br />
$tarr = array(<br />
" ",<br />
"<\1\2\3>", //如果要直接清除不安全的标签,这里可以留空<br />
"\1\2",<br />
);<br />
<br />
$str = preg_replace( $farr,$tarr,$str);<br />
return $str;<br />
<br />
}<br />
<br />
ob_start<br />
(PHP 4, PHP 5)<br />
ob_start -- Turn on output buffering打开输出缓冲<br />
<br />
ob_get_contents<br />
(PHP 4, PHP 5)<br />
ob_get_contents -- Return the contents of the output buffer 返回输出缓冲区的内容<br />
<br />
ob_end_clean<br />
(PHP 4, PHP 5)<br />
ob_end_clean -- Clean (erase) the output buffer and turn off output buffering 清洁(删除<br />
<br />
)输出缓冲区并关闭输出缓冲<br />
<br />
<br />
<br />
file_put_contents() Definition and Usage定义和用法<br />
The file_put_contents() writes a string to a file.<br />
file_put_contents()函数的作用是:将一个字符串写入文件。<br />
This function follows these rules when accessing a file:<br />
当访问一个文件是,函数必须遵循下面这些法则:<br />
1.If FILE_USE_INCLUDE_PATH is set, check the include path for a copy of *filename*<br />
如果设置了FILE_USE_INCLUDE_PATH,那么将检查*filename*副本的内置路径<br />
2.Create the file if it does not exist<br />
如果文件不存在,将创建一个文件<br />
3.Open the file<br />
打开文件<br />
4.Lock the file if LOCK_EX is set<br />
如果设置了LOCK_EX,那将对文件上锁<br />
5.If FILE_APPEND is set, move to the end of the file. Otherwise, clear the file content<br />
如果设置了FILE_APPEND,那么将移至文件末尾;否则的话,将会清除文件的内容<br />
6.Write the data into the file<br />
向文件中写入数据<br />
7.Close the file and release any locks<br />
关闭文件并对所有文件解锁<br />
This function returns the number of character written into the file on success, or FALSE<br />
<br />
on failure.<br />
如果函数运行成功,将返回写入文件中的字符数量;如果失败,则返回False。<br />
<br />
<br />
这样子做静态页面好么?<br />
ob_start();<br />
require "index.php";<br />
$str=ob_get_contents();<br />
ob_end_clean();<br />
echo $str;</object的过滤<br></scrīpt></p>