今天才看到csdn blog加入了[code]功能
并且很幸运的有小语种php……
随便开了个以前写的php文件
测试一下
<?
php
/*
comment.inc.php
*处理评论的函数
*/

require_once
(
'
conf.inc.php
'
);
require_once
(
'
func.inc.php
'
);

function
comments_gen_struct()
{
$cmts
=
array
();
return
$cmts
;
}

function
comment_one_gen_struct(
$eid
,
$content
,
$uid
=
""
,
$time
=
""
)
{
if
(
$uid
===
""
)
$uid
=
get_current_usr_name();
if
(
$time
===
""
)
$time
=
date
(
"
Y-m-d H:i:s
"
);
$cmt
=
array
(
'
eid
'
=>
$eid
,
'
uid
'
=>
$uid
,
'
time
'
=>
$time
,
'
content
'
=>
$content
);
return
$cmt
;
}

function
comment_one2html(
$one_cmnt
,
$eid
,
$cid
)
{
$html
=
"
<table width='100%' border='0' cellpadding='0' cellspace='0'><tr><td align='left'>
"
;
if
(is_admin())
{
$html
.=
"
<a href='del_comment.php?eid=$eid&cid=$cid'>删除</a>
"
;
}
//
$html.="<a href='user.php?uid=".$one_cmnt['uid']."' target='_new'>".$one_cmnt['uid']."</a>说:</td>";
$html
.=
$one_cmnt
[
'
uid
'
]
.
"
说:</td>
"
;
$html
.=
"
<td align='right'>发表于
"
.
$one_cmnt
[
'
time
'
]
.
"
</td></tr></table>
"
;
$html
.=
"
<hr size='2' align='center' noshade width='100%' color='Purple' />
"
.
$one_cmnt
[
'
content
'
];
return
$html
;
}

function
comment_struct2html(
$cmnt_struct
,
$eid
)
{
$html
=
"
<table width='100%' border='0' cellpadding='10'><tr><td class='row0'>评论:</td></tr>
"
;
$color
=
1
;
foreach
(
$cmnt_struct
as
$k
=>
$c
)
{
$color
=
3
-
$color
;
$html
.=
"
<tr><td class='row$color'>
"
.
comment_one2html(
$c
,
$eid
,
$k
)
.
"
</td></tr>
"
;
}
$html
.=
"
</table>
"
;
return
$html
;
}

function
comment_get_by_eid(
$eid
)
{
global
$conf
;
$rslt
=
db_query(
"
SELECT `comments` FROM `
"
.
$conf
[
'
TBL
'
][
'
ARTICLE
'
]
.
"
` WHERE `eid`=$eid;
"
);
$row
=
db_fetch_array(
$rslt
);
return
unserialize
(
$row
[
'
comments
'
]);
}

function
comment_add(
$eid
,
$content
,
$uid
=
""
,
$time
=
""
)
{
global
$conf
;
$c
=
comment_get_by_eid(
$eid
);
$c
[]
=
comment_one_gen_struct(
$eid
,
$content
,
$uid
,
$time
);
db_query(
"
UPDATE `
"
.
$conf
[
'
TBL
'
][
'
ARTICLE
'
]
.
"
` SET `comments`='
"
.
serialize
(
$c
)
.
"
' WHERE `eid`='$eid';
"
);
}

function
comment_del(
$eid
,
$cid
)
{
global
$conf
;
$c
=
comment_get_by_eid(
$eid
);
unset
(
$c
[
$cid
]);
db_query(
"
UPDATE `
"
.
$conf
[
'
TBL
'
][
'
ARTICLE
'
]
.
"
` SET `comments`='
"
.
serialize
(
$c
)
.
"
' WHERE `eid`='$eid';
"
);
}

function
comment_not_allow(
$eid
)
{
global
$conf
;
db_query(
"
UPDATE `
"
.
$conf
[
'
TBL
'
][
'
ARTICLE
'
]
.
"
` SET `allow_comment`='false' WHERE `eid`='$eid';
"
);
}

function
comment_allow(
$eid
)
{
global
$conf
;
$rslt
=
db_query(
"
UPDATE `
"
.
$conf
[
'
TBL
'
][
'
ARTICLE
'
]
.
"
` SET `allow_comment`='true' WHERE `eid`='$eid';
"
);
}
?>
效果不错
划分还可以再细腻一点,比如说字符串,单引号,双引号,内置变量($_开头)
并且很幸运的有小语种php……
随便开了个以前写的php文件
测试一下
























































































效果不错
划分还可以再细腻一点,比如说字符串,单引号,双引号,内置变量($_开头)