PHP Judging today is the first few weeks of the month PHP has a very powerful system function date () function. Clever use of him can be achieved by displaying any time we need. Today, for example, there is a need to judge today is the first few weeks of this month, here is not to discuss the question and whether it is meaningful, the following concrete see how to use PHP to implement this function. This function mainly uses the date () function of the W J two parameters,Date() A lot of function parameters, want to understand this function of the reference site article: PHPDate() parameter description The explanation for the two parameters of W J is as follows: W represents the day of the week, and the number indicates0 (indication Sunday) to 6(for Saturday) the day of the J month, the number indicates the1 to 31using PHP to determine the number of weeks today is the specific algorithm is: the use of the date (that is) and the total number of days of the week (7 days) of the relationship, borrowing ceil () function directly concluded today is the first few weeks of this month. Ceil() function is used to calculate a value greater than the specified number (floating-pointfloat Number) is the smallest integer. For example: Suppose that 3rd is Thursday, then,Ceil(3/7) The value will be 1, which indicates that the day is the first Thursday of the month. The next Thursday calculation isCeil(10/7) with a value of 2, indicating that 10th is the second Thursday. Other, and so on. Based on this algorithm, you can determine the calculation formula to calculate the number of weeks in the month that is today is set to:Ceil(Date/7). Let's look at a specific example:<?PHP/*function: Calculate the number of weeks of today's month*/Header(' content-type:text/html; Charset=utf-8 ');$wk _day=Date(' W ');//get today is the day of the week$date _now=Date(' J ');//What's the date today?$wkday _ar=Array(' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' VI ');//normalize the expression of the Sunday$cal _result=Ceil($date _now/7);//calculation is the first few weeks$str=Date("Y-year N-month J-Day"). " Week. "$wkday _ar[$wk _day]. "-This month's section."$cal _result. "A week".$wkday _ar[$wk _day];Echo $str;?>May 21, 2013 Tuesday-3rd Tuesday of the Month
PHP Judging today is the first few weeks of this month