八个比特

几个有用的function

字数统计: 705阅读时长: 3 min
2019/04/07 Share

来源:typecho显示网站已运行时间函数;
/**

* 秒转时间,格式 年 月 日 时 分 秒
*
* @author Roogle
* @return html
*/
function getBuildTime(){
    // 在下面按格式输入本站创建的时间
    $site_create_time = strtotime('2010-09-10 00:00:00');
    $time = time() - $site_create_time;
    if(is_numeric($time)){
        $value = array(
        "years" => 0, "days" => 0, "hours" => 0,
        "minutes" => 0, "seconds" => 0,
        );
    if($time >= 31556926){
        $value["years"] = floor($time/31556926);
        $time = ($time%31556926);
    }
    if($time >= 86400){
        $value["days"] = floor($time/86400);
        $time = ($time%86400);
    }
    if($time >= 3600){
        $value["hours"] = floor($time/3600);
        $time = ($time%3600);
    }
    if($time >= 60){
        $value["minutes"] = floor($time/60);
        $time = ($time%60);
    }
    $value["seconds"] = floor($time);
    echo '<span class="btime">'.$value['years'].'年'.$value['days'].'天'.$value['hours'].'小时'.$value['minutes'].'分</span>';
    }
    else{
    echo '';
    }
}

输出:

<?php getBuildTime(); ?>

来源:给Typecho添加页面加载时间代码

/**
* 加载时间
* @return bool
*/
function timer_start(){
    global $timestart;
    $mtime=explode(' ',microtime());
    $timestart=$mtime[1]+$mtime[0];
    return true;
    }
timer_start();
function timer_stop($display=0,$precision=3){
    global $timestart,$timeend;
    $mtime=explode(' ',microtime());
    $timeend=$mtime[1]+$mtime[0];
    $tietotal=number_format($timeend-$timestart,$precision);
    $r=$timetotal <1?$timetotal*1000."ms":$timetotal."s";
    if($display){
        echo $r;
    }
    return $r;
}

输出:

<?php echo timer_stop();?>

来源:
js搞定网页的简繁转换
tw_cn.js这里下载

<script type="text/javascript" src="tw_cn.js"></script>     
<script type="text/JavaScript" language="JavaScript">
    function s22t(){
        document.body.innerHTML=s2t(document.body.innerHTML);
    }
    function t22s(){
        document.body.innerHTML=t2s(document.body.innerHTML);
    }
</script>
//在footer.php中加入

调用:

<a href="javascript:s22t()">繁体中文</a><a href="javascript:t22s()">简体中文</a>

友链按钮:
‘’’

交换没有硬性条件限制,不涉黄不涉政非营销站即可。




<!DOCTYPE html>


*上面的按钮点一百下就会出现彩蛋哦~

‘’’

CATALOG