解读_inc.php文件各函数的意义

2025-05-31 20:41:48

1、header("Content-type:text/html;charset=UTF-8");【header() 函数向东戳缨蜇客户端发送原始的 HTTP 报头。认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 PHP 4 以及更高的版本中,您可以使用输出缓存来解决此问题):】@session_start();【@是为了抑制错误显示,让用户看不到,提升用户体验。注意:只是抑制错误,但是错误还是存在的。】require_once("./_config.php");require_once("./_cfg.php");require "inc/mysql.php";require "inc/func.php";require "inc/sql.php";【以上即请求导入这5个php文件,_config.php为配置文件,_cfg.php为网站设置参数文件,mysql.php为数据库处理函数类,sql.php为数据库处理函数文件,func.php为函数库】一般_inc.php指include即包含进网站运行需要的相关文件。

解读_inc.php文件各函数的意义

2、function phphtml($str){if($GLOBALS['cfg_html']){return $str.".html";}else{return $str.".php";}}【函数phphtml的意思是判断全局变量(在_cfg.php中有过定义)cfg_html是否设置,如果值为真,即有设置,则返回传递来的参数$str末尾加上.html标示,否则加上.php标示。这个函数的意义即为传递来的参数加上对应的网页文件后标。】

解读_inc.php文件各函数的意义

3、function classhtml($a,$b){if($GLOBALS['cfg_html']){return $a."-$b.html";}else{return $a.".php?classid=$b";}}【此函数传参两个,首先判断全局变量cfg_html是否为空,若非,则返回类似于aa-3.html的字符串,否则返回累死aa.php?classid=3这样的字符串。这个函数主要是为articles.php页面即列表页面服务的。】

解读_inc.php文件各函数的意义

4、function chtml($a,$b){if($GLOBALS['cfg_html']){return $a."-$b.html";}else{return $a.".php?id=$b";}}【此函数在判断全局变量cfg_html是否为空,若非空返回类似aa-1.html的字符串,若是则返回类似aa.php?id=1这样的字符串。这个函数主要是为article.php页面即内容页面服务的。】

5、function xia($str){$data="<div id='subs'>";$classid=$GLOBALS['db']->v("my_cata|classid|classname='$str'");$result=$GLOBALS['db']->q("select classid,classname from my_cata where fid='$classid' order by ordernum desc,classid asc");while($rows=mysql_fetch_array($result)){if($GLOBALS['cfg_html']){$data.="<span><a href=\"articles-".$rows['classid'].".html\">" . $rows['classname'] . "</a></span>";}else{$data.="<span><a href=\"articles.php?classid=".$rows['classid']."\">" . $rows['classname'] . "</a></span>";}}$data.="</div>";echo $data;}【1.$GLOBALS['var']是外部的全局变量本身 2.global $var是外部$var的同名引用或者指针。$GLOBALS 包含一个引用指向每个当前脚本的全局范围内有效的变量。该数组的键名为全局变量的名称。从 PHP 3 开始存在 $GLOBALS 数组。db类中的v函数是一个分割函数,返回classid值,而q函数则是一个查询函数,返回查询状态码。xia函数的意思是给data变量赋值一个html前置标签,用传来的参数str赋值给classname再去数据库表my_cata中去找对应的classid,然后讲classid赋值给fid,按ordernum降序,classid升序排列查找classid及classname值返回。其意义应该是取值二级分类然后以html语言输出。】

解读_inc.php文件各函数的意义

6、function xia1($str){$data="";$classid=$GLOBALS['d芟鲠阻缒b']->v("my_cata|classid|classname='$str'");$result=$GLOBALS['db']->q("select classid,classname from my_cata where fid='$classid' order by ordernum desc,classid asc limit 0,3");while($rows=mysql_fetch_array($result)){if($GLOBALS['cfg_html']){$data.="<div class='lin'><a href=\"articles-".$rows['classid'].".html\">" . $rows['classname'] . "</a></div>";}else{$data.="<div class='lin'><a href=\"articles.php?classid=".$rows['classid']."\">" . $rows['classname'] . "</a></div>";}}$data.="";echo $data;}【这个函数与上面一个xia函数类似,不过取值只有3个。】

解读_inc.php文件各函数的意义

7、function ac($a,$b){$data="";$classid=$GLOBALS['db']->v("my_cata|classid|classname='$b'");if($GLOBALS['cfg_html']){$data="$a-$classid.html";}else{$data="$a.php?classid=$classid";}$url=$GLOBALS['db']->v("my_cata|url|classname='$b'")."";if($url!=""){$data=$url;}echo $data;}【通过参数b取值classid并进行赋值操作。通过参数b取值url,判断是否为空,输出这个url值。】

解读_inc.php文件各函数的意义

8、function acbyclassid($a,$b){$data="";$classid=$GLOBALS['db']->v("my_cata|classid|classid='$b'");if($GLOBALS['cfg_html']){$data="$a-$classid".".html";}else{$data="$a.php?classid=$classid";}$url=$GLOBALS['db']->v("my_cata|url|classid='$b'")."";if($url!=""){$data=$url;}echo $data;}【此函数的作用取值参数b到数据库中提取classid=b的一组数据,返回classid值,经过对全部变量cfg_html是否为空的判断,进行赋值操作。同理url也如此。】

解读_inc.php文件各函数的意义

9、function ic($a,$b){$data="";$classid=$GLOBALS['db']->v("my_cate|classid|classname='$b'");if($GLOBALS['cfg_html']){$data="$a-$classid.html";}else{$data="$a.php?classid=$classid";}$url=$GLOBALS['db']->v("my_cate|url|classname='$b'")."";if($url!=""){$data=$url;}echo $data;}【这个函数是对my_cate数据表的取值判断及赋值】

解读_inc.php文件各函数的意义

10、function icbyclassid($a,$b){$data="";$classid=$GLOBALS['db']->v("my_cate|classid|classid='$b'");if($GLOBALS['cfg_html']){$data="$a-$classid.html";}else{$data="$a.php?classid=$classid";}$url=$GLOBALS['db']->v("my_cate|url|classid='$b'")."";if($url!=""){$data=$url;}echo $data;}【这个函数是对my_cate数据表的取值判断及赋值。这个与ic函数不同的是传值赋值给了classid而非classname。】

解读_inc.php文件各函数的意义

11、function getads($str){$data="";$data=$GLOBALS['db']->v("my_ad|content|code='$str'");echo $data;}【从my_ad数据表中取值。返回content值。】

解读_inc.php文件各函数的意义

12、function aclassids($a){$data="";$result=$GLOBALS['稆糨孝汶;db']->q("select classid from my_cata where sorts like '%|" . $a . "|%'");echo $data;}【此函数按sorts字段取值。获取到classid值。】$mxdata=strtotime(date("Y-m-d H:i:s",time()));【将字符串转换为时间格式,依后面指定的格式。time() 函数返回当前时间的 Unix 时间戳。date()转换格式。strtotime("2012-11-02 08:36:51");这个是字符串转换成时间戳数据库读出来就这样写strtotime($rs['posttime']);time()这个是输出当前时间的时间戳strtotime还可以这样用,自己试试echo(strtotime("now"));echo(strtotime("3 October 2005"));echo(strtotime("+5 hours"));echo(strtotime("+1 week"));echo(strtotime("+1 week 3 days 7 hours 5 seconds"));echo(strtotime("next Monday"));echo(strtotime("last Sunday"));】

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢