这个倒计时脚本在过去的几年里一直有效。脚本没有任何变化,但时间没有改变,所以我假设代码已被弃用。
以下是脚本的不同部分:
HTML
<img src="http://example.com/countdown.php" />
PHP - 倒计时.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 - 倒计时脚本.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 的香草测试环境中工作,但我无法让它在 PHP5.4 上工作,显然不推荐使用 5.4 的代码?