这个倒计时脚本适用于过去几年。脚本没有任何改变,但时间已经改变,所以我假设代码已经弃用了。
以下是该脚本的不同部分:
HTML
<img src="http://example.com/countdown.php" />
PHP - countdown.php
<?php
header ("content-type: image/jpg");
$echo = file_get_contents("http://example.com/countdown-script.php");
$string = "".$echo."";
$font = 8;
$width = ImageFontWidth($font)* 48;
$height = ImageFontHeight($font);
$im = ImageCreateFromjpeg("http://example.com/countdown.jpg");
$x=imagesx($im)-$width;
$y=imagesy($im)-$height;
$background_color = imagecolorallocate ($im, 0, 0, 0);
$text_color = imagecolorallocate ($im, 250, 84, 5);
$border = 5;
imagestring ($im, $font, $x, $y, $string, $text_color);
imagejpeg ($im, '', 100);
?>
PHP - countdown-script.php
<?php
countdown(2012,10,31,0,0,0);
function countdown($year, $month, $day, $hour, $minute, $second)
{
$the_countdown_date = gmmktime($hour, $minute, $second, $month, $day, $year);
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
$seconds_left = floor($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60);
echo "".$days_left." Days, ".$hours_left." Hours, ".$minutes_left." Minutes, ".$seconds_left." Seconds Left";
}
?>
虽然它用于显示countdown.jpg,顶部有文字倒计时,但它只是显示为已损坏的图像或默认为alt标记(如果使用)。
它使用PHP5.2在我的vanilla测试环境中工作,但我不能在PHP5.4上工作,显然已经弃用了5.4的代码?