Skip to content

Instantly share code, notes, and snippets.

@robinWongM
Last active December 17, 2015 07:49
Show Gist options
  • Select an option

  • Save robinWongM/5575965 to your computer and use it in GitHub Desktop.

Select an option

Save robinWongM/5575965 to your computer and use it in GitHub Desktop.
中考倒计时范例
<?php
// 以下代码仅供参考
$now = getdate(); //现在时间
$nowtime = mktime(0,0,0,$now['mon'],$now['mday'],$now['year']); //现在时间的Unix时间戳
$zhongkao = mktime(0,0,0,6,20,2013); //2013.6.20
$remaining = $zhongkao - $nowtime; //如果需要正数,则用$nowtime - $zhongkao
$days = strval($remaining / 86400); //转换成天数,84600 = 60 * 60 * 24
$split = preg_split("//",$days,0,PREG_SPLIT_NO_EMPTY);//分割成组成数字的每一个数字,例如38分割成3和8
foreach($split as $number)//一个一个输出
{
echo ('<img src="http://1.labcdn.sinaapp.com/cd/' . $number .'.png" />' . "\n");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment