我需要修改此代码的帮助,以创建一个网页,其中包含生日(从出生那天到今年的生日)以及每个日期对应的星期几
#!/usr/local/bin/php
<?php print '<?xml version="1.0" encoding="utf-8" ?> '; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Title</title>
</head>
<body>
<?php
date_default_timezone_set('America/Los_Angeles');
$year = 1997;
$ts = mktime(0,0,0,1,1,$year);
for($day=1; $day < 32; $day++)
{
echo date('n/j/Y', $ts), "was a ", date('l', $ts), "<br/>";
$ts += 24*3600;
}
?>
</body>
</html>
答案 0 :(得分:1)
您需要将mktime()
命令移至循环的内部。另外,不知道为什么要在循环结束时将时间戳记增加一天,所以也将其删除:
<?php
date_default_timezone_set('America/Los_Angeles');
$year = 1997;
for($year; $year < 2018; $year++) {
$ts = mktime(0, 0, 0, 8, 20, $year);
echo date('n/j/Y', $ts), " was a ", date('l', $ts), "<br/>";
}
?>