English 中文(简体)
网址:www.un.org
原标题:php function returns false
  • 时间:2012-01-15 18:26:29
  •  标签:
  • php

The following PHP function Return the nthweekday of a个月, e.g. the 3rd日星期三 in January 2012 in form 18-1-2012:

<?php
  function giveNthDay($month, $year, $no, $day) {
     $counter = 0;
     for($i=1;$i<=31;$i++) { //Schleife für 31 Tage
         if(!checkdate($month, $i, $year)) { //wenn datum nicht existiert (bspw. 30. februar) zu nächstem schleifendurchlauf springen
             continue;
         } else {
             if(date( l , strtotime($i. - .$month. - .$year))==$day) { //wenn generiertes Datum gleicher Wochentag wie gesuchter Tag $day
                 $counter++; //dann $counter um eins erhöhen
                 if($counter==$no) { //falls $counter==$no, also falls bspw. DRITTER ($no==$counter==3) Mittwoch gefunden, Datum zurückgeben
                     return     $i. - .$month. - .$year;
                 }
             }
         }
     }
     return false; //existiert nicht, bspw. fünfter Sonntag gibt es nicht in jedem Monat
  }
?>

如果存在日期(例如2012年1月的第5周),那就错了。

比如:

giveNthDay(1, 2012, 3, "Wednesday");
giveNthDay(1, 2020, 3, "Wednesday");
giveNthDay(1, 2031, 3, "Wednesday");

but from

giveNthDay(1, 2038, 3, "Wednesday");

on, it returns false even though every January has more than 3 Wednesdays!

I tried hard to find out what the reason for this strange behaviour is but I can t figure it out. Can anyone help me?

最佳回答

2038年不属于范围,最长为2037年(关于32个轨道结构)。 <代码>时间()为不定的时间范围(自1970-1 00:00起)。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签