A simple perpetual calendar function _php Tutorial

Source: Internet
Author: User
A few days ago need a perpetual calendar function, on the Oso saw a perpetual calendar, program function to is strong, but too cumbersome.
Do not have their own requirements, so they wrote one, you can also add a connection to the date!
function Calendar ($year, $moon) {
$moon 1=array ("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
$moon 2=array ("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
if (($year -2000)%4==0) {$moon 2[1]=29;}
for ($i =0; $i <=11; $i + +) {
if ($moon 1[$i]== $moon) {
$total = $moon 2[$i];
}
}
$out _chat= "";
$out _chat.= "Day 123456";
for ($i =1; $i <= $total; $i + +) {
$j = $i;
if ($i <10) {
$j = "0". $i;
}
$time _array=getdate (Mktime (0,0,0, $moon, $j, $year));
if ($i ==1) {
Switch ($time _array[wday]) {
Case "0":
$out _chat.= "". $i. "";
Break
Case "1":
$out _chat.= "". $i. "";
Break
Case "2":
$out _chat.= "". $i. "";
Break
Case "3":
$out _chat.= "". $i. "";
Break
Case "4":
$out _chat.= "". $i. "";

Break
Case "5":
$out _chat.= "". $i. "";
Break
Case "6":
$out _chat.= "". $i. "";
Break
}
}else{
if ($i! = $total) {
if ($time _array[wday]!=0) {
$out _chat.= "". $i. "";
}else{
$out _chat.= "". $i. "";
}
}elseif ($i = = $total) {
Switch ($time _array[wday]) {
Case "0":
$out _chat.= "". $i. " ";
Break
Case "1":
$out _chat.= "". $i. " ";
Break
Case "2":
$out _chat.= "". $i. " ";
Break
Case "3":
$out _chat.= "". $i. " ";
Break
Case "4":
$out _chat.= "". $i. " ";
Break
Case "5":
$out _chat.= "". $i. " ";
Break
Case "6":
$out _chat.= "". $i. "";
Break
}
}
}
}
$out _chat.= "";
return $out _chat;
}

$year = 2000;
$moon = 08;
$test =calendar ($year, $moon);
Echo $test;
?>

http://www.bkjia.com/PHPjc/532214.html www.bkjia.com true http://www.bkjia.com/PHPjc/532214.html techarticle //A few days ago need a perpetual calendar function, on the Oso saw a perpetual calendar, program function to is strong, but too cumbersome. Do not have their own requirements, so I wrote a, can also ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.