PDA

View Full Version : مبتدی: تحلیل کد تقویم



soheil19php
پنج شنبه 30 دی 1395, 10:08 صبح
سلام
امیدوارم خوب باشین! من این کد تمرینی از کتاب کار کردم ولی همه جاشو متوجه نشدم اون جاهایی که فهمیدم کامنت کردم بخصوص از لاین 58 به بعد نفهمیدم ! اگه میشه دوستان اون قسمت به بعد

برام توضیح بدن ممنون میشم




<?php
define("ADAY", (60*60*24));
if (!checkdate(@$_POST['month'], 1, @$_POST['year'])) { //1esh vase chie line 24 bebad bebin
$nowArray = getdate();//getdate(timestamp);zaman halo gereft ta maho salesho faghat bedas biare
$month = $nowArray['mon'];
$year = $nowArray['year'];
//تو این قسمت با استفاده از تابع گت دیت زمان فعلی را گرفته و حال ماه و سال فعلی را درمتغییرها قرار میدهد
} else {
$month = $_POST['month'];//age check date ghalat nabood yani tarikh varede karbar sahih bood
$year = $_POST['year'];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
//mk time() timestamp misaze pas time stamp zaman feli ro ba moshkhasat khase mktime(yani saat 12 va rooze 1om(to get time avval faghat mikhastim maho sal bedas biarim hamin) ) bedast miarim sepas ba get date zaman mored nazaro bedas miarim
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']." ".$firstDayArray['year'] // line 13 ?>
</title>
<head>
<body>
<h3>Select a Month/Year Combination</h3>
<form method="post" action="<?php echo "$_SERVER[PHP_SELF]"; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December");
for ($x=1; $x <= count($months); $x++) { //count tedad anasor araye ro neshun mide
echo"<option value=\"$x\"";// soal beshe in ghesmat mishe inotriam nevesht(echo"<option value=".$x.' ';)
if ($x == $month) {
echo " SELECTED";
}
echo ">".$months[$x-1]."";//baraye inke az x=1 to for shoroo kardim intori kard ta $x[0] ham hesab she
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<=2020; $x++) {
echo "<option";
if ($x == $year) {
echo " SELECTED";
}
echo ">$x";
}
?>
</select>
<input type="submit" value="Go!">
</form>
<br>
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<TABLE BORDER=1 CELLPADDING=5><tr>\n";
foreach ($days as $day) {
echo "<TD BGCOLOR=\"#CCCCCC\" ALIGN=CENTER>
<strong>$day</strong></td>\n";
}
//az in line be bad tozih bede nmifahmam ziad
for ($count=0; $count < (6*7); $count++) {//chera 6*7???
$dayArray = getdate($start);//day array jadide moteghayeresh,$start ham line 12(zaman mored nazar)
if (($count % 7) == 0) { //chrea inkaro kard??
if ($dayArray['mon'] != $month) {
break;
} else { //else vase chi dad??
echo "</tr><tr>\n";
}
}
if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month) {// age count roozi koochiktar az rooze hafte(0 ta 6) bashe ya aslan mahesh ba $month motebaghat nadashte bashe
echo "<td>&nbsp;</td>\n";//satr khali chap kon
} else {
echo "<td>".$dayArray['mday']." &nbsp;&nbsp; </td>\n";
$start += ADAY;// yani chi??
}
}
echo "</tr></table>";
?>
</body>
</html>




بازم ممنون