2013-05-14 00:04
采纳率: 0%
浏览 63

php mktime函数产生奇怪的符号

I am trying to adapt a calendar script by David Walsh. In David's script showing a monthly calendar, for the first week it shows blanks before the month start but a commenter said you can use following code to display the dates from the previous month ie 28 20 30 depending on when the first day of the month falls.

I won't repeat all of the code from the script linked to, but the main thing is that the replacement code displays a symbol I have never seen before.., �30�. (I have copied these symbols from he source. They are squares that say FF above PD.). Here is code. Note $x, $running_day and $daysInThisWeek are just numbers. $calendar gets echoed at end.

//following prints out empty table cells

for($x = 0; $x < $running_day; $x++):
        $calendar.= '<td class="calendar-day-np">&nbsp;</td>';
echo $calendar;

//But following, echoed, prints out wierd symbols:

$daysInLastMonth = date(‘t’,mktime(0,0,0,$month-1,1,$year));

Then when you loop through as above you get a whole bunch of the wierd symbols.

for($x = 0; $x < $running_day; $x++): //this line is same as above
$calendar.= ' . ( ( $daysInLastMonth – ( $runningDay – 1 ) ) + $x ). ';
echo $calendar;

Does anyone know what might be going on, what the wierd symbols mean and how to get this to display properly.

Thanks for any suggestions!

图片转代码服务由CSDN问答提供 功能建议

我正在尝试通过 David Walsh 。 在David的脚本中显示月度日历,第一周它在月份开始前显示空白,但是评论者说您可以使用以下代码显示上个月的日期,即28 20 30,具体取决于每月的第一天何时下降 。

我不会重复链接到的脚本中的所有代码,但主要的是替换代码显示我以前从未见过的符号..,�30� 。 (我从他的来源复制了这些符号。他们是在PD之上说FF的正方形。)。 这是代码。 注意$ x,$ running_day和$ daysInThisWeek只是数字。 $ calendar在结尾处回显。

for($ x = 0; $ x&lt; $ running_day; $ x ++):  
 $ calendar。='&lt; td class =“calendar-day-np”&gt;&amp; nbsp;&lt; / td&gt;'; 
 $ days_in_this_week ++; 
echo $ calendar; 


  $ daysInLastMonth = date('t',mktime(  0,0,0,$ month-1,1,$ year)); 

然后当你如上所述循环时,你会得到一大堆奇怪的东西 符号。

  for($ x = 0; $ x&lt; $ running_day; $ x ++)://此行与上面的
 $ calendar。='相同。  (($ daysInLastMonth  - ($ runningDay  -  1))+ $ x)。  '; 
 $ daysInThisWeek ++; 
echo $ calendar; 

有谁知道可能会发生什么,奇怪的符号是什么意思以及如何获得 这可以正常显示。


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douchen5971
    douchen5971 2013-05-14 00:11

    Turn on all errors and you will see that you have wrong quotes. Errors would be like

    Notice: Use of undefined constant ‘t’ - assumed '‘t’'

    This line

    $daysInLastMonth = date(‘t’,mktime(0,0,0,$month-1,1,$year));

    must be

    $daysInLastMonth = date('t',mktime(0,0,0,$month-1,1,$year));
    点赞 评论
  • dongtan1009
    dongtan1009 2013-05-14 00:21

    There is a mistake with:

    $daysInLastMonth = date(‘t’,mktime(0,0,0,$month-1,1,$year));

    It should be:

    $daysInLastMonth = date('t',mktime(0,0,0,$month-1,1,$year));

    To notice that kind of mistake you have to turn on errors:


    More information about PHP errors in:

    About the characters it seems to be a encoding issue:

    These links will help you:

    UTF-8 all the way through

    点赞 评论