The code is as follows:
<span 1</span> <?<span php </span><span 2</span> <span /*</span><span * </span><span 3</span> <span * </span><span 4</span> <span * 我的日历 </span><span 5</span> <span * date_default_timezone_set date mktime </span><span 6</span> <span * @param int $year </span><span 7</span> <span * @param int $month </span><span 8</span> <span * @param string $timezone </span><span 9</span> <span * @author fc_lamp </span><span 10</span> <span * @blog: http://www.cnblogs.com/roucheng/ </span><span 11</span> <span */</span> <span 12</span> <span function</span> myCalender(<span $year</span> = '', <span $month</span> = '', <span $timezone</span> = 'Asia/Shanghai'<span ) </span><span 13</span> <span { </span><span 14</span> <span 15</span> date_default_timezone_set ( <span $timezone</span><span ); </span><span 16</span> <span $year</span> = <span abs</span> ( <span intval</span> ( <span $year</span><span ) ); </span><span 17</span> <span $month</span> = <span abs</span> ( <span intval</span> ( <span $month</span><span ) ); </span><span 18</span> <span 19</span> <span //</span><span 是否是32位机</span> <span 20</span> <span if</span><span (is32()) </span><span 21</span> <span { </span><span 22</span> <span if</span> (<span $year</span> < 1970 or <span $year</span> >= 2038<span ) </span><span 23</span> <span { </span><span 24</span> <span $year</span> = <span date</span> ( 'Y'<span ); </span><span 25</span> <span } </span><span 26</span> } <span else</span> <span 27</span> <span { </span><span 28</span> <span if</span> (<span $year</span> <= 0<span ) </span><span 29</span> <span { </span><span 30</span> <span $year</span> = <span date</span> ( 'Y'<span ); </span><span 31</span> <span } </span><span 32</span> <span 33</span> <span } </span><span 34</span> <span 35</span> <span if</span> (<span $month</span> <= 0 or <span $month</span> > 12<span ) </span><span 36</span> <span { </span><span 37</span> <span $month</span> = <span date</span> ( 'm'<span ); </span><span 38</span> <span } </span><span 39</span> <span 40</span> <span //</span><span 上一年</span> <span 41</span> <span $pretYear</span> = <span $year</span> - 1<span ; </span><span 42</span> <span //</span><span 上一月</span> <span 43</span> <span $mpYear</span> = <span $year</span><span ; </span><span 44</span> <span $preMonth</span> = <span $month</span> - 1<span ; </span><span 45</span> <span if</span> (<span $preMonth</span> <= 0<span ) </span><span 46</span> <span { </span><span 47</span> <span $preMonth</span> = 1<span ; </span><span 48</span> <span $mpYear</span> = <span $pretYear</span><span ; </span><span 49</span> <span } </span><span 50</span> <span 51</span> <span //</span><span 下一年</span> <span 52</span> <span $nextYear</span> = <span $year</span> + 1<span ; </span><span 53</span> <span //</span><span 下一月</span> <span 54</span> <span $mnYear</span> = <span $year</span><span ; </span><span 55</span> <span $nextMonth</span> = <span $month</span> + 1<span ; </span><span 56</span> <span if</span> (<span $nextMonth</span> > 12<span ) </span><span 57</span> <span { </span><span 58</span> <span $nextMonth</span> = 1<span ; </span><span 59</span> <span $mnYear</span> = <span $nextYear</span><span ; </span><span 60</span> <span } </span><span 61</span> <span 62</span> <span //</span><span 日历头</span> <span 63</span> <span $html</span> = <<<<span HTML </span><span 64</span> <table width="500" border="1"> <span 65</span> <tr align="center"> <span 66</span> <td><a href="?y=<span $pretYear</span>">上一年</a></td> <span 67</span> <td><a href="?y=<span $mpYear</span>&m=<span $preMonth</span>">上一月</a></td> <span 68</span> <td><a href="?">回到今天</a></td> <span 69</span> <td><a href="?y=<span $mnYear</span>&m=<span $nextMonth</span>">下一月</a></td> <span 70</span> <td><a href="?y=<span $nextYear</span>">下一年</a></td> <span 71</span> </tr> <span 72</span> <tr align="center"> <span 73</span> <td colspan="5">{<span $year</span>}年{<span $month</span>}月</td> <span 74</span> </tr> <span 75</span> <tr> <span 76</span> <td colspan="5"> <span 77</span> <table width="100%" border="1"> <span 78</span> <tr align="center"> <span 79</span> <td 80</span> <td 81</span> <td 82</span> <td 83</span> <td 84</span> <td 85</span> <td 86</span> </tr> <span 87</span> <span HTML; </span><span 88</span> <span 89</span> <span $currentDay</span> = <span date</span> ( 'Y-m-j'<span ); </span><span 90</span> <span 91</span> <span //</span><span 当月最后一天</span> <span 92</span> <span $lastday</span> = <span date</span> ( 'j', <span mktime</span> ( 0, 0, 0, <span $nextMonth</span>, 0, <span $year</span><span ) ); </span><span 93</span> <span 94</span> <span //</span><span 循环输出天数</span> <span 95</span> <span $day</span> = 1<span ; </span><span 96</span> <span $line</span> = ''<span ; </span><span 97</span> <span while</span> ( <span $day</span> <= <span $lastday</span><span ) </span><span 98</span> <span { </span><span 99</span> <span $cday</span> = <span $year</span> . '-' . <span $month</span> . '-' . <span $day</span><span ; </span><span 100</span> <span 101</span> <span //</span><span 当前星期几</span> <span 102</span> <span $nowWeek</span> = <span date</span> ( 'N', <span mktime</span> ( 0, 0, 0, <span $month</span>, <span $day</span>, <span $year</span><span ) ); </span><span 103</span> <span 104</span> <span if</span> (<span $day</span> == 1<span ) </span><span 105</span> <span { </span><span 106</span> <span $line</span> = '<tr align="center">'<span ; </span><span 107</span> <span $line</span> .= <span str_repeat</span> ( '<td> </td>', <span $nowWeek</span> - 1<span ); </span><span 108</span> <span } </span><span 109</span> <span 110</span> <span if</span> (<span $cday</span> == <span $currentDay</span><span ) </span><span 111</span> <span { </span><span 112</span> <span $style</span> = '; </span><span 113</span> } <span else</span> <span 114</span> <span { </span><span 115</span> <span $style</span> = ''<span ; </span><span 116</span> <span } </span><span 117</span> <span 118</span> <span $line</span> .= "<td <span $style</span>><span $day</span></td>"<span ; </span><span 119</span> <span 120</span> <span //</span><span 一周结束</span> <span 121</span> <span if</span> (<span $nowWeek</span> == 7<span ) </span><span 122</span> <span { </span><span 123</span> <span $line</span> .= '</tr>'<span ; </span><span 124</span> <span $html</span> .= <span $line</span><span ; </span><span 125</span> <span $line</span> = '<tr align="center">'<span ; </span><span 126</span> <span } </span><span 127</span> <span 128</span> <span //</span><span 全月结束</span> <span 129</span> <span if</span> (<span $day</span> == <span $lastday</span><span ) </span><span 130</span> <span { </span><span 131</span> <span if</span> (<span $nowWeek</span> != 7<span ) </span><span 132</span> <span { </span><span 133</span> <span $line</span> .= <span str_repeat</span> ( '<td> </td>', 7 - <span $nowWeek</span><span ); </span><span 134</span> <span } </span><span 135</span> <span $line</span> .= '</tr>'<span ; </span><span 136</span> <span $html</span> .= <span $line</span><span ; </span><span 137</span> <span 138</span> <span break</span><span ; </span><span 139</span> <span } </span><span 140</span> <span 141</span> <span $day</span> ++<span ; </span><span 142</span> <span } </span><span 143</span> <span 144</span> <span $html</span> .= <<<<span HTML </span><span 145</span> </table> <span 146</span> </td> <span 147</span> </tr> <span 148</span> </table> <span 149</span> <span HTML; </span><span 150</span> <span return</span> <span $html</span><span ; </span><span 151</span> <span } </span><span 152</span> <span 153</span> <span /*</span><span * </span><span 154</span> <span * </span><span 155</span> <span * 检测是否是32位机 </span><span 156</span> <span * @author fc_lamp </span><span 157</span> <span * @blog: fc-lamp.blog.163.com </span><span 158</span> <span */</span> <span 159</span> <span function</span><span is32() </span><span 160</span> <span { </span><span 161</span> <span $is32</span> = <span False</span><span ; </span><span 162</span> <span if</span> (<span strtotime</span> ( '2039-10-10' ) === <span False</span><span ) </span><span 163</span> <span { </span><span 164</span> <span $is32</span> = <span True</span><span ; </span><span 165</span> <span } </span><span 166</span> <span return</span> <span $is32</span><span ; </span><span 167</span> }

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
