2012-03-19 63 views
1

我剛剛開始了我的PHP旅程,並且正在完成創建簡單日曆的教程。我遇到了一個鍵盤上的語法錯誤,一直沒能找到修復。我確信這很簡單,我沒有看到。對於筆記抱歉,我一直試圖儘可能多地註釋,所以我不會迷路。PHP初學者...簡單的PHP語法錯誤

的錯誤是:

Parse error: syntax error, unexpected ',' on line 10. (the $day=('d', $date) declaration) 

代碼:

<?php 

// current date variable 

$date = time(); 


//day, month and year variables 

$day = ('d', $date); 
$month = ('m', $date); 
$year = ('Y', $date); 


// first day of the month 

$monthfirstday = mktime(0,0,0,$month, 1, $year); 


// get the name of the month 

$monthtitle = ('F', $monthfirstday); 


// first day of the week 

$weekday = ('D', $monthfirstday); 


// identify the days of the week 

switch ($weekday) { 
    case"Sun": $blank=0; 
    break; 
    case"Mon": $blank=1; 
    break; 
    case"Tue": $blank=2; 
    break; 
    case"Wed": $blank=3; 
    break; 
    case"Thu": $blank=4; 
    break; 
    case"Fri": $blank=5; 
    break; 
    case"Sat": $blank=6; 
    break; 
} 


// number of days in the month 

$daysinmonth = cal_days_in_month(0, $month, $year); 


// include the html 

echo "<div id='calendar-wrap'>"; 
echo "<table border=6 width=394><tr><th colspan=60> $monthtitle $year</th></tr>"; 
echo " 
    <tr> 
     \n\t\t<td width=62>SUN</td> 
     \n\t\t<td width=62>MON</td> 
     \n\t\t<td width=62>TUES</td> 
     \n\t\t<td width=62>WEDS</td> 
     \n\t\t<td width=62>THURS</td> 
     \n\t\t<td width=62>FRI</td> 
     \n\t\t<td width=62>SAT</td> 
     </tr> 
"; 


$daycount = 1; 

echo "<tr>"; 


// dealing with the days of the month 

$blank > 0 
{ 
echo "<td></td>"; 
$blank = $blank-1; 
$daycount++; 
}   


// set the day number to 1 

$daynumber = 1; 


// count the days of the month 

while 
($daynumber <= $daysinmonth) 
{ 
echo "<td> $daynumber </td>"; 


// increase the day count until the month ends 

$daynumber++; 
$daycount++; 


// add a new row every 7 days 

if ($daycount > 7) 
{ 
echo "</tr><tr>"; 
$daycount = 1; 
} 
} 

// fill in blank days if necessary 

while 
($daycount > 1 && $daycount <= 7) 
{ 
echo "<td> </td>"; 
$daycount++; 
} 

echo "</tr></table></div>"; 

?> 

由於提前,

邁克

+7

您需要'$ day = date('d',$ date);' – scibuff 2012-03-19 17:28:43

回答

6

你的功能缺失!

$day = date('d', $date); 
+0

oh man ... *臉紅* – TheNally 2012-03-19 17:32:26

3

在這裏你去...

$day = date('d', $date); 
$month = date('m', $date); 
$year = date('Y', $date); 
1

我想你想做到這一點:

$day = date('d', $date); 
0

這是錯誤。錯過了功能:)

$day = date('d', $date); 
$month = date('m', $date); 
$year = date('Y', $date);