ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 自定义函数数据函数fn 保存base64图片 ``` <pre class="calibre14">``` <span class="token5">if</span> <span class="token2">(</span><span class="token1">preg_match</span><span class="token2">(</span><span class="token4">'/^(data:\s*image\/(\w+);base64,)/'</span><span class="token2">,</span> $img<span class="token2">,</span> $result<span class="token2">)</span><span class="token2">)</span> <span class="token2">{</span> $type <span class="token">=</span> <span class="token4">"."</span><span class="token2">.</span>$result<span class="token2">[</span><span class="token3">2</span><span class="token2">]</span><span class="token2">;</span> $path <span class="token">=</span> <span class="token4">"/data/upload/api/"</span> <span class="token2">.</span> <span class="token1">date</span><span class="token2">(</span><span class="token4">"Y-m-d"</span><span class="token2">)</span> <span class="token2">.</span> <span class="token4">"-"</span> <span class="token2">.</span> <span class="token1">uniqid</span><span class="token2">(</span><span class="token2">)</span> <span class="token2">.</span> $type<span class="token2">;</span> <span class="token2">}</span> $img <span class="token">=</span> <span class="token1">base64_decode</span><span class="token2">(</span><span class="token1">str_replace</span><span class="token2">(</span>$result<span class="token2">[</span><span class="token3">1</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">''</span><span class="token2">,</span> $img<span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> @<span class="token1">file_put_contents</span><span class="token2">(</span>HX_ROOT <span class="token2">.</span> $path<span class="token2">,</span> $img<span class="token2">)</span><span class="token2">;</span> ``` ``` 百度编辑器 需要预先加载 ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">ueditor</span><span class="token2">(</span>$id<span class="token">=</span><span class="token4">"content"</span><span class="token2">,</span>$value<span class="token">=</span><span class="token4">""</span><span class="token2">,</span>$height<span class="token">=</span><span class="token4">"250"</span><span class="token2">)</span><span class="token2">{</span> $host <span class="token">=</span> SITE_URL<span class="token2">;</span> $str <span class="token">=</span><span class="token"><</span><span class="token"><</span><span class="token"><</span>EOF <span class="token"><</span>script id<span class="token">=</span><span class="token4">"{$id}"</span> name<span class="token">=</span><span class="token4">"{$id}"</span> type<span class="token">=</span><span class="token4">"text/plain"</span><span class="token">></span> <span class="token2">{</span>$value<span class="token2">}</span> <span class="token"><</span><span class="token">/</span>script<span class="token">></span> <span class="token"><</span>script type<span class="token">=</span><span class="token4">"text/javascript"</span><span class="token">></span> var ue <span class="token">=</span> UE<span class="token2">.</span><span class="token1">getEditor</span><span class="token2">(</span><span class="token4">"{$id}"</span><span class="token2">,</span><span class="token2">{</span> initialFrameHeight<span class="token2">:</span>$height<span class="token2">,</span>allowDivTransToP<span class="token2">:</span><span class="token3">false</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token"><</span><span class="token">/</span>script<span class="token">></span> EOF<span class="token2">;</span> <span class="token5">return</span> $str<span class="token2">;</span> <span class="token2">}</span> ``` ``` 时区数组 ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">get_timezone</span><span class="token2">(</span><span class="token2">)</span><span class="token2">{</span> <span class="token5">return</span> <span class="token1">array</span><span class="token2">(</span> <span class="token4">'Pacific/Kwajalein'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -12:00) Eniwetok, Kwajalein'</span><span class="token2">,</span> <span class="token4">'Pacific/Samoa'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -11:00) Midway Island, Samoa'</span><span class="token2">,</span> <span class="token4">'US/Hawaii'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -10:00) Hawaii'</span><span class="token2">,</span> <span class="token4">'US/Alaska'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -09:00) Alaska'</span><span class="token2">,</span> <span class="token4">'America/Tijuana'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -08:00) Pacific Time (US & Canada), Tijuana'</span><span class="token2">,</span> <span class="token4">'US/Arizona'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -07:00) Mountain Time (US & Canada), Arizona'</span><span class="token2">,</span> <span class="token4">'America/Mexico_City'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -06:00) Central Time (US & Canada), Mexico City'</span><span class="token2">,</span> <span class="token4">'America/Bogota'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -05:00) Eastern Time (US & Canada), Bogota, Lima, Quito'</span><span class="token2">,</span> <span class="token4">'America/Caracas'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -04:00) Atlantic Time (Canada), Caracas, La Paz'</span><span class="token2">,</span> <span class="token4">'Canada/Newfoundland'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -03:30) Newfoundland'</span><span class="token2">,</span> <span class="token4">'America/Buenos_Aires'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -03:00) Brassila, Buenos Aires, Georgetown, Falkland Is'</span><span class="token2">,</span> <span class="token4">'Atlantic/St_Helena'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -02:00) Mid-Atlantic, Ascension Is., St. Helena'</span><span class="token2">,</span> <span class="token4">'Atlantic/Azores'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT -01:00) Azores, Cape Verde Islands'</span><span class="token2">,</span> <span class="token4">'Europe/Dublin'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia'</span><span class="token2">,</span> <span class="token4">'Europe/Amsterdam'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +01:00) Amsterdam, Berlin, Brussels, Madrid, Paris, Rome'</span><span class="token2">,</span> <span class="token4">'Africa/Cairo'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +02:00) Cairo, Helsinki, Kaliningrad, South Africa'</span><span class="token2">,</span> <span class="token4">'Asia/Baghdad'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +03:00) Baghdad, Riyadh, Moscow, Nairobi'</span><span class="token2">,</span> <span class="token4">'Asia/Tehran'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +03:30) Tehran'</span><span class="token2">,</span> <span class="token4">'Asia/Baku'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +04:00) Abu Dhabi, Baku, Muscat, Tbilisi'</span><span class="token2">,</span> <span class="token4">'Asia/Kabul'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +04:30) Kabul'</span><span class="token2">,</span> <span class="token4">'Asia/Karachi'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +05:00) Ekaterinburg, Islamabad, Karachi, Tashkent'</span><span class="token2">,</span> <span class="token4">'Asia/Calcutta'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +05:30) Bombay, Calcutta, Madras, New Delhi'</span><span class="token2">,</span> <span class="token4">'Asia/Katmandu'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +05:45) Katmandu'</span><span class="token2">,</span> <span class="token4">'Asia/Almaty'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +06:00) Almaty, Colombo, Dhaka, Novosibirsk'</span><span class="token2">,</span> <span class="token4">'Asia/Rangoon'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +06:30) Rangoon'</span><span class="token2">,</span> <span class="token4">'Asia/Bangkok'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +07:00) Bangkok, Hanoi, Jakarta'</span><span class="token2">,</span> <span class="token4">'Asia/Shanghai'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +08:00) Beijing, Hong Kong, Perth, Singapore, Taipei'</span><span class="token2">,</span> <span class="token4">'Asia/Tokyo'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +09:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk'</span><span class="token2">,</span> <span class="token4">'Australia/Adelaide'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +09:30) Adelaide, Darwin'</span><span class="token2">,</span> <span class="token4">'Australia/Canberra'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +10:00) Canberra, Guam, Melbourne, Sydney, Vladivostok'</span><span class="token2">,</span> <span class="token4">'Asia/Magadan'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +11:00) Magadan, New Caledonia, Solomon Islands'</span><span class="token2">,</span> <span class="token4">'Pacific/Auckland'</span><span class="token">=</span><span class="token">></span><span class="token4">'(GMT +12:00) Auckland, Wellington, Fiji, Marshall Island'</span> <span class="token2">)</span><span class="token2">;</span> ``` ``` 天气现象数组 ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">weather</span><span class="token2">(</span><span class="token2">)</span><span class="token2">{</span> <span class="token5">return</span> <span class="token1">array</span><span class="token2">(</span> <span class="token4">"00"</span> <span class="token">=</span><span class="token">></span><span class="token4">"晴"</span><span class="token2">,</span> <span class="token4">"01"</span><span class="token">=</span><span class="token">></span><span class="token4">"多云"</span><span class="token2">,</span> <span class="token4">"02"</span><span class="token">=</span><span class="token">></span><span class="token4">"阴"</span><span class="token2">,</span> <span class="token4">"03"</span><span class="token">=</span><span class="token">></span><span class="token4">"阵雨"</span><span class="token2">,</span> <span class="token4">"04"</span><span class="token">=</span><span class="token">></span><span class="token4">"雷阵雨"</span><span class="token2">,</span> <span class="token4">"05"</span><span class="token">=</span><span class="token">></span><span class="token4">"雷阵雨伴有冰雹"</span><span class="token2">,</span> <span class="token4">"06"</span><span class="token">=</span><span class="token">></span><span class="token4">"雨夹雪"</span><span class="token2">,</span> <span class="token4">"07"</span><span class="token">=</span><span class="token">></span><span class="token4">"小雨"</span><span class="token2">,</span> <span class="token4">"08"</span><span class="token">=</span><span class="token">></span><span class="token4">"中雨"</span><span class="token2">,</span> <span class="token4">"09"</span><span class="token">=</span><span class="token">></span><span class="token4">"大雨"</span><span class="token2">,</span> <span class="token4">"10"</span><span class="token">=</span><span class="token">></span><span class="token4">"暴雨"</span><span class="token2">,</span> <span class="token4">"11"</span><span class="token">=</span><span class="token">></span><span class="token4">"大暴雨"</span><span class="token2">,</span> <span class="token4">"12"</span><span class="token">=</span><span class="token">></span><span class="token4">"特大暴雨"</span><span class="token2">,</span> <span class="token4">"13"</span><span class="token">=</span><span class="token">></span><span class="token4">"阵雪"</span><span class="token2">,</span> <span class="token4">"14"</span><span class="token">=</span><span class="token">></span><span class="token4">"小雪"</span><span class="token2">,</span> <span class="token4">"15"</span><span class="token">=</span><span class="token">></span><span class="token4">"中雪"</span><span class="token2">,</span> <span class="token4">"16"</span><span class="token">=</span><span class="token">></span><span class="token4">"大雪"</span><span class="token2">,</span> <span class="token4">"17"</span><span class="token">=</span><span class="token">></span><span class="token4">"暴雪"</span><span class="token2">,</span> <span class="token4">"18"</span><span class="token">=</span><span class="token">></span><span class="token4">"雾"</span><span class="token2">,</span> <span class="token4">"19"</span><span class="token">=</span><span class="token">></span><span class="token4">"冻雨"</span><span class="token2">,</span> <span class="token4">"20"</span><span class="token">=</span><span class="token">></span><span class="token4">"沙尘暴"</span><span class="token2">,</span> <span class="token4">"21"</span><span class="token">=</span><span class="token">></span><span class="token4">"小到中雨"</span><span class="token2">,</span> <span class="token4">"22"</span><span class="token">=</span><span class="token">></span><span class="token4">"中到大雨"</span><span class="token2">,</span> <span class="token4">"23"</span><span class="token">=</span><span class="token">></span><span class="token4">"大到暴雨"</span><span class="token2">,</span> <span class="token4">"24"</span><span class="token">=</span><span class="token">></span><span class="token4">"暴雨到大暴雨"</span><span class="token2">,</span> <span class="token4">"25"</span><span class="token">=</span><span class="token">></span><span class="token4">"大暴雨到特大暴雨"</span><span class="token2">,</span> <span class="token4">"26"</span><span class="token">=</span><span class="token">></span><span class="token4">"小到中雪"</span><span class="token2">,</span> <span class="token4">"27"</span><span class="token">=</span><span class="token">></span><span class="token4">"中到大雪"</span><span class="token2">,</span> <span class="token4">"28"</span><span class="token">=</span><span class="token">></span><span class="token4">"大到暴雪"</span><span class="token2">,</span> <span class="token4">"29"</span><span class="token">=</span><span class="token">></span><span class="token4">"浮尘"</span><span class="token2">,</span> <span class="token4">"30"</span><span class="token">=</span><span class="token">></span><span class="token4">"扬沙"</span><span class="token2">,</span> <span class="token4">"31"</span><span class="token">=</span><span class="token">></span><span class="token4">"强沙尘暴"</span><span class="token2">,</span> <span class="token4">"53"</span><span class="token">=</span><span class="token">></span><span class="token4">"霾"</span><span class="token2">,</span> <span class="token4">"99"</span><span class="token">=</span><span class="token">></span><span class="token4">"无"</span><span class="token2">,</span> <span class="token4">"32"</span><span class="token">=</span><span class="token">></span><span class="token4">"浓雾"</span><span class="token2">,</span> <span class="token4">"49"</span><span class="token">=</span><span class="token">></span><span class="token4">"强浓雾"</span><span class="token2">,</span> <span class="token4">"54"</span><span class="token">=</span><span class="token">></span><span class="token4">"中度霾"</span><span class="token2">,</span> <span class="token4">"55"</span><span class="token">=</span><span class="token">></span><span class="token4">"重度霾"</span><span class="token2">,</span> <span class="token4">"56"</span><span class="token">=</span><span class="token">></span><span class="token4">"严重霾"</span><span class="token2">,</span> <span class="token4">"57"</span><span class="token">=</span><span class="token">></span><span class="token4">"大雾"</span><span class="token2">,</span> <span class="token4">"58"</span><span class="token">=</span><span class="token">></span><span class="token4">"特强浓雾"</span><span class="token2">,</span> <span class="token4">"301"</span><span class="token">=</span><span class="token">></span><span class="token4">"雨"</span><span class="token2">,</span> <span class="token4">"302"</span><span class="token">=</span><span class="token">></span><span class="token4">"雪"</span> <span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> ``` ``` /\* 获取文件MIME类型,根据文件扩展名来获取 \*/ ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">getFileType</span><span class="token2">(</span>$ext<span class="token2">)</span><span class="token2">{</span> static $mime_types <span class="token">=</span> array <span class="token2">(</span> <span class="token4">'apk'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.android.package-archive'</span><span class="token2">,</span> <span class="token4">'3gp'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/3gpp'</span><span class="token2">,</span> <span class="token4">'ai'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/postscript'</span><span class="token2">,</span> <span class="token4">'aif'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/x-aiff'</span><span class="token2">,</span> <span class="token4">'aifc'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/x-aiff'</span><span class="token2">,</span> <span class="token4">'aiff'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/x-aiff'</span><span class="token2">,</span> <span class="token4">'asc'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/plain'</span><span class="token2">,</span> <span class="token4">'atom'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/atom+xml'</span><span class="token2">,</span> <span class="token4">'au'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/basic'</span><span class="token2">,</span> <span class="token4">'avi'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/x-msvideo'</span><span class="token2">,</span> <span class="token4">'bcpio'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-bcpio'</span><span class="token2">,</span> <span class="token4">'bin'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'bmp'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/bmp'</span><span class="token2">,</span> <span class="token4">'cdf'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-netcdf'</span><span class="token2">,</span> <span class="token4">'cgm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/cgm'</span><span class="token2">,</span> <span class="token4">'class'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'cpio'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-cpio'</span><span class="token2">,</span> <span class="token4">'cpt'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/mac-compactpro'</span><span class="token2">,</span> <span class="token4">'csh'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-csh'</span><span class="token2">,</span> <span class="token4">'css'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/css'</span><span class="token2">,</span> <span class="token4">'dcr'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-director'</span><span class="token2">,</span> <span class="token4">'dif'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/x-dv'</span><span class="token2">,</span> <span class="token4">'dir'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-director'</span><span class="token2">,</span> <span class="token4">'djv'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/vnd.djvu'</span><span class="token2">,</span> <span class="token4">'djvu'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/vnd.djvu'</span><span class="token2">,</span> <span class="token4">'dll'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'dmg'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'dms'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'doc'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/msword'</span><span class="token2">,</span> <span class="token4">'dtd'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/xml-dtd'</span><span class="token2">,</span> <span class="token4">'dv'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/x-dv'</span><span class="token2">,</span> <span class="token4">'dvi'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-dvi'</span><span class="token2">,</span> <span class="token4">'dxr'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-director'</span><span class="token2">,</span> <span class="token4">'eps'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/postscript'</span><span class="token2">,</span> <span class="token4">'etx'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/x-setext'</span><span class="token2">,</span> <span class="token4">'exe'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'ez'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/andrew-inset'</span><span class="token2">,</span> <span class="token4">'flv'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/x-flv'</span><span class="token2">,</span> <span class="token4">'gif'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/gif'</span><span class="token2">,</span> <span class="token4">'gram'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/srgs'</span><span class="token2">,</span> <span class="token4">'grxml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/srgs+xml'</span><span class="token2">,</span> <span class="token4">'gtar'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-gtar'</span><span class="token2">,</span> <span class="token4">'gz'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-gzip'</span><span class="token2">,</span> <span class="token4">'hdf'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-hdf'</span><span class="token2">,</span> <span class="token4">'hqx'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/mac-binhex40'</span><span class="token2">,</span> <span class="token4">'htm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/html'</span><span class="token2">,</span> <span class="token4">'html'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/html'</span><span class="token2">,</span> <span class="token4">'ice'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'x-conference/x-cooltalk'</span><span class="token2">,</span> <span class="token4">'ico'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-icon'</span><span class="token2">,</span> <span class="token4">'ics'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/calendar'</span><span class="token2">,</span> <span class="token4">'ief'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/ief'</span><span class="token2">,</span> <span class="token4">'ifb'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/calendar'</span><span class="token2">,</span> <span class="token4">'iges'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'model/iges'</span><span class="token2">,</span> <span class="token4">'igs'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'model/iges'</span><span class="token2">,</span> <span class="token4">'jnlp'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-java-jnlp-file'</span><span class="token2">,</span> <span class="token4">'jp2'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/jp2'</span><span class="token2">,</span> <span class="token4">'jpe'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/jpeg'</span><span class="token2">,</span> <span class="token4">'jpeg'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/jpeg'</span><span class="token2">,</span> <span class="token4">'jpg'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/jpeg'</span><span class="token2">,</span> <span class="token4">'js'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-javascript'</span><span class="token2">,</span> <span class="token4">'kar'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/midi'</span><span class="token2">,</span> <span class="token4">'latex'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-latex'</span><span class="token2">,</span> <span class="token4">'lha'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'lzh'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'m3u'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/x-mpegurl'</span><span class="token2">,</span> <span class="token4">'m4a'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/mp4a-latm'</span><span class="token2">,</span> <span class="token4">'m4p'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/mp4a-latm'</span><span class="token2">,</span> <span class="token4">'m4u'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/vnd.mpegurl'</span><span class="token2">,</span> <span class="token4">'m4v'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/x-m4v'</span><span class="token2">,</span> <span class="token4">'mac'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-macpaint'</span><span class="token2">,</span> <span class="token4">'man'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-troff-man'</span><span class="token2">,</span> <span class="token4">'mathml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/mathml+xml'</span><span class="token2">,</span> <span class="token4">'me'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-troff-me'</span><span class="token2">,</span> <span class="token4">'mesh'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'model/mesh'</span><span class="token2">,</span> <span class="token4">'mid'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/midi'</span><span class="token2">,</span> <span class="token4">'midi'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/midi'</span><span class="token2">,</span> <span class="token4">'mif'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.mif'</span><span class="token2">,</span> <span class="token4">'mov'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/quicktime'</span><span class="token2">,</span> <span class="token4">'movie'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/x-sgi-movie'</span><span class="token2">,</span> <span class="token4">'mp2'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/mpeg'</span><span class="token2">,</span> <span class="token4">'mp3'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/mpeg'</span><span class="token2">,</span> <span class="token4">'mp4'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/mp4'</span><span class="token2">,</span> <span class="token4">'mpe'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/mpeg'</span><span class="token2">,</span> <span class="token4">'mpeg'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/mpeg'</span><span class="token2">,</span> <span class="token4">'mpg'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/mpeg'</span><span class="token2">,</span> <span class="token4">'mpga'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/mpeg'</span><span class="token2">,</span> <span class="token4">'ms'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-troff-ms'</span><span class="token2">,</span> <span class="token4">'msh'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'model/mesh'</span><span class="token2">,</span> <span class="token4">'mxu'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/vnd.mpegurl'</span><span class="token2">,</span> <span class="token4">'nc'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-netcdf'</span><span class="token2">,</span> <span class="token4">'oda'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/oda'</span><span class="token2">,</span> <span class="token4">'ogg'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/ogg'</span><span class="token2">,</span> <span class="token4">'ogv'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/ogv'</span><span class="token2">,</span> <span class="token4">'pbm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-portable-bitmap'</span><span class="token2">,</span> <span class="token4">'pct'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/pict'</span><span class="token2">,</span> <span class="token4">'pdb'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'chemical/x-pdb'</span><span class="token2">,</span> <span class="token4">'pdf'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/pdf'</span><span class="token2">,</span> <span class="token4">'pgm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-portable-graymap'</span><span class="token2">,</span> <span class="token4">'pgn'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-chess-pgn'</span><span class="token2">,</span> <span class="token4">'pic'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/pict'</span><span class="token2">,</span> <span class="token4">'pict'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/pict'</span><span class="token2">,</span> <span class="token4">'png'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/png'</span><span class="token2">,</span> <span class="token4">'pnm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-portable-anymap'</span><span class="token2">,</span> <span class="token4">'pnt'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-macpaint'</span><span class="token2">,</span> <span class="token4">'pntg'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-macpaint'</span><span class="token2">,</span> <span class="token4">'ppm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-portable-pixmap'</span><span class="token2">,</span> <span class="token4">'ppt'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.ms-powerpoint'</span><span class="token2">,</span> <span class="token4">'ps'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/postscript'</span><span class="token2">,</span> <span class="token4">'qt'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/quicktime'</span><span class="token2">,</span> <span class="token4">'qti'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-quicktime'</span><span class="token2">,</span> <span class="token4">'qtif'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-quicktime'</span><span class="token2">,</span> <span class="token4">'ra'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/x-pn-realaudio'</span><span class="token2">,</span> <span class="token4">'ram'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/x-pn-realaudio'</span><span class="token2">,</span> <span class="token4">'ras'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-cmu-raster'</span><span class="token2">,</span> <span class="token4">'rdf'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/rdf+xml'</span><span class="token2">,</span> <span class="token4">'rgb'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-rgb'</span><span class="token2">,</span> <span class="token4">'rm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.rn-realmedia'</span><span class="token2">,</span> <span class="token4">'roff'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-troff'</span><span class="token2">,</span> <span class="token4">'rtf'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/rtf'</span><span class="token2">,</span> <span class="token4">'rtx'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/richtext'</span><span class="token2">,</span> <span class="token4">'sgm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/sgml'</span><span class="token2">,</span> <span class="token4">'sgml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/sgml'</span><span class="token2">,</span> <span class="token4">'sh'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-sh'</span><span class="token2">,</span> <span class="token4">'shar'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-shar'</span><span class="token2">,</span> <span class="token4">'silo'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'model/mesh'</span><span class="token2">,</span> <span class="token4">'sit'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-stuffit'</span><span class="token2">,</span> <span class="token4">'skd'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-koan'</span><span class="token2">,</span> <span class="token4">'skm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-koan'</span><span class="token2">,</span> <span class="token4">'skp'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-koan'</span><span class="token2">,</span> <span class="token4">'skt'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-koan'</span><span class="token2">,</span> <span class="token4">'smi'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/smil'</span><span class="token2">,</span> <span class="token4">'smil'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/smil'</span><span class="token2">,</span> <span class="token4">'snd'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/basic'</span><span class="token2">,</span> <span class="token4">'so'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/octet-stream'</span><span class="token2">,</span> <span class="token4">'spl'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-futuresplash'</span><span class="token2">,</span> <span class="token4">'src'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-wais-source'</span><span class="token2">,</span> <span class="token4">'sv4cpio'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-sv4cpio'</span><span class="token2">,</span> <span class="token4">'sv4crc'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-sv4crc'</span><span class="token2">,</span> <span class="token4">'svg'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/svg+xml'</span><span class="token2">,</span> <span class="token4">'swf'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-shockwave-flash'</span><span class="token2">,</span> <span class="token4">'t'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-troff'</span><span class="token2">,</span> <span class="token4">'tar'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-tar'</span><span class="token2">,</span> <span class="token4">'tcl'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-tcl'</span><span class="token2">,</span> <span class="token4">'tex'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-tex'</span><span class="token2">,</span> <span class="token4">'texi'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-texinfo'</span><span class="token2">,</span> <span class="token4">'texinfo'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-texinfo'</span><span class="token2">,</span> <span class="token4">'tif'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/tiff'</span><span class="token2">,</span> <span class="token4">'tiff'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/tiff'</span><span class="token2">,</span> <span class="token4">'tr'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-troff'</span><span class="token2">,</span> <span class="token4">'tsv'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/tab-separated-values'</span><span class="token2">,</span> <span class="token4">'txt'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/plain'</span><span class="token2">,</span> <span class="token4">'ustar'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-ustar'</span><span class="token2">,</span> <span class="token4">'vcd'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/x-cdlink'</span><span class="token2">,</span> <span class="token4">'vrml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'model/vrml'</span><span class="token2">,</span> <span class="token4">'vxml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/voicexml+xml'</span><span class="token2">,</span> <span class="token4">'wav'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'audio/x-wav'</span><span class="token2">,</span> <span class="token4">'wbmp'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/vnd.wap.wbmp'</span><span class="token2">,</span> <span class="token4">'wbxml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.wap.wbxml'</span><span class="token2">,</span> <span class="token4">'webm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/webm'</span><span class="token2">,</span> <span class="token4">'wml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/vnd.wap.wml'</span><span class="token2">,</span> <span class="token4">'wmlc'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.wap.wmlc'</span><span class="token2">,</span> <span class="token4">'wmls'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'text/vnd.wap.wmlscript'</span><span class="token2">,</span> <span class="token4">'wmlsc'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.wap.wmlscriptc'</span><span class="token2">,</span> <span class="token4">'wmv'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'video/x-ms-wmv'</span><span class="token2">,</span> <span class="token4">'wrl'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'model/vrml'</span><span class="token2">,</span> <span class="token4">'xbm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-xbitmap'</span><span class="token2">,</span> <span class="token4">'xht'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/xhtml+xml'</span><span class="token2">,</span> <span class="token4">'xhtml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/xhtml+xml'</span><span class="token2">,</span> <span class="token4">'xls'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.ms-excel'</span><span class="token2">,</span> <span class="token4">'xml'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/xml'</span><span class="token2">,</span> <span class="token4">'xpm'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-xpixmap'</span><span class="token2">,</span> <span class="token4">'xsl'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/xml'</span><span class="token2">,</span> <span class="token4">'xslt'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/xslt+xml'</span><span class="token2">,</span> <span class="token4">'xul'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/vnd.mozilla.xul+xml'</span><span class="token2">,</span> <span class="token4">'xwd'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image/x-xwindowdump'</span><span class="token2">,</span> <span class="token4">'xyz'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'chemical/x-xyz'</span><span class="token2">,</span> <span class="token4">'zip'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'application/zip'</span> <span class="token2">)</span><span class="token2">;</span> <span class="token5">return</span> <span class="token1">isset</span><span class="token2">(</span>$mime_types<span class="token2">[</span>$ext<span class="token2">]</span><span class="token2">)</span> <span class="token">?</span> $mime_types<span class="token2">[</span>$ext<span class="token2">]</span> <span class="token2">:</span> <span class="token4">'application/octet-stream'</span><span class="token2">;</span> <span class="token2">}</span> ``` ``` /\*\* - 表格转换数组 - @param $table 表格html代码 - @return array \*/ ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">tableArr</span><span class="token2">(</span>$table<span class="token2">)</span> <span class="token2">{</span> $table <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">"'<table[^>]*?>'si"</span><span class="token2">,</span> <span class="token4">""</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> $table <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">"'<tr[^>]*?>'si"</span><span class="token2">,</span> <span class="token4">""</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> $table <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">"'<td[^>]*?>'si"</span><span class="token2">,</span> <span class="token4">""</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> $table <span class="token">=</span> <span class="token1">str_replace</span><span class="token2">(</span><span class="token4">"</tr>"</span><span class="token2">,</span> <span class="token4">"{tr}"</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> $table <span class="token">=</span> <span class="token1">str_replace</span><span class="token2">(</span><span class="token4">"</td>"</span><span class="token2">,</span> <span class="token4">"{td}"</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> <span class="token6">//去掉 HTML 标记</span> $table <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">"'<[/!]*?[^<>]*?>'si"</span><span class="token2">,</span> <span class="token4">""</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> <span class="token6">//去掉空白字符</span> $table <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">"'([rn])[s]+'"</span><span class="token2">,</span> <span class="token4">""</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> $table <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">'/&nbsp;/'</span><span class="token2">,</span> <span class="token4">""</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> $table <span class="token">=</span> <span class="token1">str_replace</span><span class="token2">(</span><span class="token4">" "</span><span class="token2">,</span> <span class="token4">""</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> $table <span class="token">=</span> <span class="token1">str_replace</span><span class="token2">(</span><span class="token4">" "</span><span class="token2">,</span> <span class="token4">""</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> $table <span class="token">=</span> <span class="token1">explode</span><span class="token2">(</span><span class="token4">'{tr}'</span><span class="token2">,</span> $table<span class="token2">)</span><span class="token2">;</span> <span class="token1">array_pop</span><span class="token2">(</span>$table<span class="token2">)</span><span class="token2">;</span> foreach <span class="token2">(</span>$table as $key <span class="token">=</span><span class="token">></span> $tr<span class="token2">)</span> <span class="token2">{</span> $td <span class="token">=</span> <span class="token1">explode</span><span class="token2">(</span><span class="token4">'{td}'</span><span class="token2">,</span> $tr<span class="token2">)</span><span class="token2">;</span> <span class="token1">array_pop</span><span class="token2">(</span>$td<span class="token2">)</span><span class="token2">;</span> $td_array<span class="token2">[</span><span class="token2">]</span> <span class="token">=</span> $td<span class="token2">;</span> <span class="token2">}</span> <span class="token5">return</span> $td_array<span class="token2">;</span> <span class="token2">}</span> ``` ``` 删除文件或文件夹,文件夹递归删除,非常危险 ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">fileDelete</span><span class="token2">(</span>$file<span class="token2">)</span><span class="token2">{</span> <span class="token5">if</span> <span class="token2">(</span><span class="token1">empty</span><span class="token2">(</span>$file<span class="token2">)</span><span class="token2">)</span> <span class="token5">return</span> <span class="token3">false</span><span class="token2">;</span> <span class="token5">if</span> <span class="token2">(</span>@<span class="token1">is_file</span><span class="token2">(</span>$file<span class="token2">)</span><span class="token2">)</span> <span class="token5">return</span> @<span class="token1">unlink</span><span class="token2">(</span>$file<span class="token2">)</span><span class="token2">;</span> $ret <span class="token">=</span> <span class="token3">true</span><span class="token2">;</span> <span class="token5">if</span> <span class="token2">(</span>$handle <span class="token">=</span> @<span class="token1">opendir</span><span class="token2">(</span>$file<span class="token2">)</span><span class="token2">)</span> <span class="token2">{</span> <span class="token5">while</span> <span class="token2">(</span>$filename <span class="token">=</span> @<span class="token1">readdir</span><span class="token2">(</span>$handle<span class="token2">)</span><span class="token2">)</span><span class="token2">{</span> <span class="token5">if</span> <span class="token2">(</span>$filename <span class="token">==</span> <span class="token4">'.'</span> <span class="token">||</span> $filename <span class="token">==</span> <span class="token4">'..'</span><span class="token2">)</span> <span class="token5">continue</span><span class="token2">;</span> <span class="token5">if</span> <span class="token2">(</span><span class="token">!</span><span class="token1">fileDelete</span><span class="token2">(</span>$file <span class="token2">.</span> <span class="token4">'/'</span> <span class="token2">.</span> $filename<span class="token2">)</span><span class="token2">)</span> $ret <span class="token">=</span> <span class="token3">false</span><span class="token2">;</span> <span class="token2">}</span> <span class="token2">}</span> <span class="token5">else</span> <span class="token2">{</span> $ret <span class="token">=</span> <span class="token3">false</span><span class="token2">;</span> <span class="token2">}</span> @<span class="token1">closedir</span><span class="token2">(</span>$handle<span class="token2">)</span><span class="token2">;</span> <span class="token5">if</span> <span class="token2">(</span> <span class="token1">file_exists</span><span class="token2">(</span>$file<span class="token2">)</span> <span class="token">&&</span> <span class="token">!</span><span class="token1">rmdir</span><span class="token2">(</span>$file<span class="token2">)</span> <span class="token2">)</span><span class="token2">{</span> $ret <span class="token">=</span> <span class="token3">false</span><span class="token2">;</span> <span class="token2">}</span> <span class="token5">return</span> $ret<span class="token2">;</span> <span class="token2">}</span> ``` ``` /\*\* - 生成avatar头像 - @param 邮箱 $email - @param 大小 $s - @param undefined $d - @param undefined $g - - @return \*/ ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">getAvatar</span><span class="token2">(</span>$email<span class="token">=</span><span class="token4">''</span><span class="token2">,</span> $s<span class="token">=</span><span class="token3">40</span><span class="token2">,</span> $d<span class="token">=</span><span class="token4">'mm'</span><span class="token2">,</span> $g<span class="token">=</span><span class="token4">'g'</span><span class="token2">)</span> <span class="token2">{</span> $hash <span class="token">=</span> <span class="token1">md5</span><span class="token2">(</span>$email<span class="token2">)</span><span class="token2">;</span> $avatar <span class="token">=</span> <span class="token4">"http://www.gravatar.com/avatar/$hash?s=$s&d=$d&r=$g"</span><span class="token2">;</span> <span class="token5">return</span> $avatar<span class="token2">;</span> <span class="token2">}</span> ``` ``` /\*\* - 加密解密函数 - ENCODE 加密 - @param $string - @param string $operation - @param string $key - @param int $expiry - @return string \*/ ``` <pre class="calibre14">``` <span class="token5">if</span> <span class="token2">(</span><span class="token">!</span><span class="token1">function_exists</span><span class="token2">(</span><span class="token4">'authcode'</span><span class="token2">)</span><span class="token2">)</span> <span class="token2">{</span> <span class="token5">function</span> <span class="token1">authcode</span><span class="token2">(</span>$string<span class="token2">,</span> $operation <span class="token">=</span> <span class="token4">'DECODE'</span><span class="token2">,</span> $key <span class="token">=</span> <span class="token4">''</span><span class="token2">,</span> $expiry <span class="token">=</span> <span class="token3">0</span><span class="token2">)</span> <span class="token2">{</span> $ckey_length <span class="token">=</span> <span class="token3">4</span><span class="token2">;</span> $keya <span class="token">=</span> <span class="token1">md5</span><span class="token2">(</span><span class="token1">substr</span><span class="token2">(</span>$key<span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">16</span><span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> $keyb <span class="token">=</span> <span class="token1">md5</span><span class="token2">(</span><span class="token1">substr</span><span class="token2">(</span>$key<span class="token2">,</span> <span class="token3">16</span><span class="token2">,</span> <span class="token3">16</span><span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> $keyc <span class="token">=</span> $ckey_length <span class="token">?</span> <span class="token2">(</span>$operation <span class="token">==</span> <span class="token4">'DECODE'</span> <span class="token">?</span> <span class="token1">substr</span><span class="token2">(</span>$string<span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> $ckey_length<span class="token2">)</span> <span class="token2">:</span> <span class="token1">substr</span><span class="token2">(</span><span class="token1">md5</span><span class="token2">(</span><span class="token1">microtime</span><span class="token2">(</span><span class="token2">)</span><span class="token2">)</span><span class="token2">,</span> <span class="token">-</span>$ckey_length<span class="token2">)</span><span class="token2">)</span> <span class="token2">:</span> <span class="token4">''</span><span class="token2">;</span> $cryptkey <span class="token">=</span> $keya <span class="token2">.</span> <span class="token1">md5</span><span class="token2">(</span>$keya <span class="token2">.</span> $keyc<span class="token2">)</span><span class="token2">;</span> $key_length <span class="token">=</span> <span class="token1">strlen</span><span class="token2">(</span>$cryptkey<span class="token2">)</span><span class="token2">;</span> $string <span class="token">=</span> $operation <span class="token">==</span> <span class="token4">'DECODE'</span> <span class="token">?</span> <span class="token1">base64_decode</span><span class="token2">(</span><span class="token1">substr</span><span class="token2">(</span>$string<span class="token2">,</span> $ckey_length<span class="token2">)</span><span class="token2">)</span> <span class="token2">:</span> <span class="token1">sprintf</span><span class="token2">(</span><span class="token4">'%010d'</span><span class="token2">,</span> $expiry <span class="token">?</span> $expiry <span class="token">+</span> <span class="token1">time</span><span class="token2">(</span><span class="token2">)</span> <span class="token2">:</span> <span class="token3">0</span><span class="token2">)</span> <span class="token2">.</span> <span class="token1">substr</span><span class="token2">(</span><span class="token1">md5</span><span class="token2">(</span>$string <span class="token2">.</span> $keyb<span class="token2">)</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">16</span><span class="token2">)</span> <span class="token2">.</span> $string<span class="token2">;</span> $string_length <span class="token">=</span> <span class="token1">strlen</span><span class="token2">(</span>$string<span class="token2">)</span><span class="token2">;</span> $result <span class="token">=</span> <span class="token4">''</span><span class="token2">;</span> $box <span class="token">=</span> <span class="token1">range</span><span class="token2">(</span><span class="token3">0</span><span class="token2">,</span> <span class="token3">255</span><span class="token2">)</span><span class="token2">;</span> $rndkey <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> <span class="token5">for</span> <span class="token2">(</span>$i <span class="token">=</span> <span class="token3">0</span><span class="token2">;</span> $i <span class="token"><=</span> <span class="token3">255</span><span class="token2">;</span> $i<span class="token">++</span><span class="token2">)</span> <span class="token2">{</span> $rndkey<span class="token2">[</span>$i<span class="token2">]</span> <span class="token">=</span> <span class="token1">ord</span><span class="token2">(</span>$cryptkey<span class="token2">[</span>$i <span class="token">%</span> $key_length<span class="token2">]</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> <span class="token5">for</span> <span class="token2">(</span>$j <span class="token">=</span> $i <span class="token">=</span> <span class="token3">0</span><span class="token2">;</span> $i <span class="token"><</span> <span class="token3">256</span><span class="token2">;</span> $i<span class="token">++</span><span class="token2">)</span> <span class="token2">{</span> $j <span class="token">=</span> <span class="token2">(</span>$j <span class="token">+</span> $box<span class="token2">[</span>$i<span class="token2">]</span> <span class="token">+</span> $rndkey<span class="token2">[</span>$i<span class="token2">]</span><span class="token2">)</span> <span class="token">%</span> <span class="token3">256</span><span class="token2">;</span> $tmp <span class="token">=</span> $box<span class="token2">[</span>$i<span class="token2">]</span><span class="token2">;</span> $box<span class="token2">[</span>$i<span class="token2">]</span> <span class="token">=</span> $box<span class="token2">[</span>$j<span class="token2">]</span><span class="token2">;</span> $box<span class="token2">[</span>$j<span class="token2">]</span> <span class="token">=</span> $tmp<span class="token2">;</span> <span class="token2">}</span> <span class="token5">for</span> <span class="token2">(</span>$a <span class="token">=</span> $j <span class="token">=</span> $i <span class="token">=</span> <span class="token3">0</span><span class="token2">;</span> $i <span class="token"><</span> $string_length<span class="token2">;</span> $i<span class="token">++</span><span class="token2">)</span> <span class="token2">{</span> $a <span class="token">=</span> <span class="token2">(</span>$a <span class="token">+</span> <span class="token3">1</span><span class="token2">)</span> <span class="token">%</span> <span class="token3">256</span><span class="token2">;</span> $j <span class="token">=</span> <span class="token2">(</span>$j <span class="token">+</span> $box<span class="token2">[</span>$a<span class="token2">]</span><span class="token2">)</span> <span class="token">%</span> <span class="token3">256</span><span class="token2">;</span> $tmp <span class="token">=</span> $box<span class="token2">[</span>$a<span class="token2">]</span><span class="token2">;</span> $box<span class="token2">[</span>$a<span class="token2">]</span> <span class="token">=</span> $box<span class="token2">[</span>$j<span class="token2">]</span><span class="token2">;</span> $box<span class="token2">[</span>$j<span class="token2">]</span> <span class="token">=</span> $tmp<span class="token2">;</span> $result <span class="token2">.</span><span class="token">=</span> <span class="token1">chr</span><span class="token2">(</span><span class="token1">ord</span><span class="token2">(</span>$string<span class="token2">[</span>$i<span class="token2">]</span><span class="token2">)</span> <span class="token">^</span> <span class="token2">(</span>$box<span class="token2">[</span><span class="token2">(</span>$box<span class="token2">[</span>$a<span class="token2">]</span> <span class="token">+</span> $box<span class="token2">[</span>$j<span class="token2">]</span><span class="token2">)</span> <span class="token">%</span> <span class="token3">256</span><span class="token2">]</span><span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> <span class="token5">if</span> <span class="token2">(</span>$operation <span class="token">==</span> <span class="token4">'DECODE'</span><span class="token2">)</span> <span class="token2">{</span> <span class="token5">if</span> <span class="token2">(</span><span class="token2">(</span><span class="token1">substr</span><span class="token2">(</span>$result<span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">10</span><span class="token2">)</span> <span class="token">==</span> <span class="token3">0</span> <span class="token">||</span> <span class="token1">substr</span><span class="token2">(</span>$result<span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">10</span><span class="token2">)</span> <span class="token">-</span> <span class="token1">time</span><span class="token2">(</span><span class="token2">)</span> <span class="token">></span> <span class="token3">0</span><span class="token2">)</span> <span class="token">&&</span> <span class="token1">substr</span><span class="token2">(</span>$result<span class="token2">,</span> <span class="token3">10</span><span class="token2">,</span> <span class="token3">16</span><span class="token2">)</span> <span class="token">==</span> <span class="token1">substr</span><span class="token2">(</span><span class="token1">md5</span><span class="token2">(</span><span class="token1">substr</span><span class="token2">(</span>$result<span class="token2">,</span> <span class="token3">26</span><span class="token2">)</span> <span class="token2">.</span> $keyb<span class="token2">)</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">16</span><span class="token2">)</span><span class="token2">)</span> <span class="token2">{</span> <span class="token5">return</span> <span class="token1">substr</span><span class="token2">(</span>$result<span class="token2">,</span> <span class="token3">26</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> <span class="token5">else</span> <span class="token2">{</span> <span class="token5">return</span> <span class="token4">''</span><span class="token2">;</span> <span class="token2">}</span> <span class="token2">}</span> <span class="token5">else</span> <span class="token2">{</span> <span class="token5">return</span> $keyc <span class="token2">.</span> <span class="token1">str_replace</span><span class="token2">(</span><span class="token4">'='</span><span class="token2">,</span> <span class="token4">''</span><span class="token2">,</span> <span class="token1">base64_encode</span><span class="token2">(</span>$result<span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> <span class="token2">}</span> <span class="token2">}</span> ``` ``` //百度地图根据ip获取经纬度,国家省市县 城市代码 ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">get_baidumap</span><span class="token2">(</span>$ip<span class="token">=</span><span class="token4">"117.81.149.14"</span><span class="token2">,</span>$ak<span class="token">=</span><span class="token4">"M4eExM3AxIcxOdnFGciErtK3"</span><span class="token2">)</span><span class="token2">{</span> $d <span class="token">=</span> <span class="token1">get</span><span class="token2">(</span><span class="token4">"https://api.map.baidu.com/location/ip?ak=$ak&coor=bd09ll&ip=$ip"</span><span class="token2">)</span><span class="token2">;</span> $d <span class="token">=</span> <span class="token1">json_decode</span><span class="token2">(</span>$d<span class="token2">,</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span> $d <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span> <span class="token4">"lon"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'content'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'point'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'x'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"lat"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'content'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'point'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'y'</span><span class="token2">]</span> <span class="token2">,</span> <span class="token4">"nation"</span> <span class="token">=</span><span class="token">></span> <span class="token4">"中国"</span><span class="token2">,</span> <span class="token4">"province"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'content'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'address_detail'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'province'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"city"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'content'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'address_detail'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'city'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"district"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'content'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'address_detail'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'district'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"citycode"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'content'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'address_detail'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'city_code'</span><span class="token2">]</span> <span class="token2">,</span> <span class="token4">"ip"</span><span class="token">=</span><span class="token">></span> $ip <span class="token2">)</span><span class="token2">;</span> <span class="token5">return</span> $d<span class="token2">;</span> <span class="token2">}</span> ``` ``` //qq地图根据ip获取经纬度,国家省市县区号 ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">get_qqmap</span><span class="token2">(</span>$ip<span class="token">=</span><span class="token4">"117.80.91.208"</span><span class="token2">,</span>$ak<span class="token">=</span><span class="token4">"ACEBZ-FDXWP-WFRDV-VGS5Q-S2Q5K-HQBNA"</span><span class="token2">)</span><span class="token2">{</span> $d <span class="token">=</span> <span class="token1">get</span><span class="token2">(</span><span class="token4">"https://apis.map.qq.com/ws/location/v1/ip?ip=$ip&key=$ak"</span><span class="token2">)</span><span class="token2">;</span> $d <span class="token">=</span> <span class="token1">json_decode</span><span class="token2">(</span>$d<span class="token2">,</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span> $d <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span> <span class="token4">"lon"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'location'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'lng'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"lat"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'location'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'lat'</span><span class="token2">]</span> <span class="token2">,</span> <span class="token4">"nation"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'ad_info'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'nation'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"province"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'ad_info'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'province'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"city"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'ad_info'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'city'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"district"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'ad_info'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'district'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"adcode"</span> <span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'ad_info'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'adcode'</span><span class="token2">]</span> <span class="token2">,</span> <span class="token4">"ip"</span><span class="token">=</span><span class="token">></span> $d<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'ip'</span><span class="token2">]</span> <span class="token2">)</span><span class="token2">;</span> <span class="token5">return</span> $d<span class="token2">;</span> <span class="token2">}</span> ``` ``` //百度天气接口 输入城市或经纬度 ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">get_weather</span><span class="token2">(</span>$city<span class="token">=</span><span class="token4">"昆山"</span><span class="token2">,</span>$ak<span class="token">=</span><span class="token4">"M4eExM3AxIcxOdnFGciErtK3"</span><span class="token2">)</span><span class="token2">{</span> $d <span class="token">=</span> <span class="token1">get</span><span class="token2">(</span><span class="token4">"http://api.map.baidu.com/telematics/v3/weather?location=$city&output=json&ak=$ak"</span><span class="token2">)</span><span class="token2">;</span> $d <span class="token">=</span> <span class="token1">json_decode</span><span class="token2">(</span>$d<span class="token2">,</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span> <span class="token5">if</span><span class="token2">(</span>$d<span class="token2">[</span><span class="token4">'error'</span><span class="token2">]</span><span class="token">==</span><span class="token3">0</span><span class="token2">)</span><span class="token2">{</span> $d <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span> <span class="token4">"date"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'date'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"city"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'results'</span><span class="token2">]</span><span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'currentCity'</span><span class="token2">]</span><span class="token2">,</span> <span class="token4">"pm25"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'results'</span><span class="token2">]</span><span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'pm25'</span><span class="token2">]</span><span class="token2">,</span> <span class="token6">//pm</span> <span class="token4">"index"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'results'</span><span class="token2">]</span><span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'index'</span><span class="token2">]</span><span class="token2">,</span> <span class="token6">//指数</span> <span class="token4">"weather_data"</span><span class="token">=</span><span class="token">></span>$d<span class="token2">[</span><span class="token4">'results'</span><span class="token2">]</span><span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'weather_data'</span><span class="token2">]</span><span class="token2">,</span> <span class="token6">//当天,3天天气</span> <span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span><span class="token5">else</span><span class="token2">{</span> $d <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> <span class="token5">return</span> $d<span class="token2">;</span> <span class="token2">}</span> ``` ``` 高德天气和ip定位 ``` <pre class="calibre16">``` <span class="token5">function</span> <span class="token1">getwether</span><span class="token2">(</span>$ak<span class="token">=</span><span class="token4">'6812110e232abd4f53d345bed23a90d3'</span><span class="token2">,</span>$ip<span class="token">=</span><span class="token4">'114.218.66.167'</span><span class="token2">)</span><span class="token2">{</span> $url <span class="token">=</span> <span class="token4">"https://restapi.amap.com/v3/ip?key=$ak&ip=$ip"</span><span class="token2">;</span> $arr <span class="token">=</span> <span class="token1">json_decode</span><span class="token2">(</span><span class="token1">get</span><span class="token2">(</span>$url<span class="token2">)</span><span class="token2">,</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span> $code <span class="token">=</span> $arr<span class="token2">[</span><span class="token4">'adcode'</span><span class="token2">]</span><span class="token2">;</span><span class="token6">//城市代码</span> $json <span class="token">=</span> <span class="token1">get</span><span class="token2">(</span><span class="token4">"https://restapi.amap.com/v3/weather/weatherInfo?key=$ak&city=$code&extensions=all"</span><span class="token2">)</span><span class="token2">;</span> $json <span class="token">=</span> <span class="token1">json_decode</span><span class="token2">(</span>$json<span class="token2">,</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span> <span class="token1">dump</span><span class="token2">(</span>$json<span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> 星座函数 <span class="token5">function</span> <span class="token1">get_cons</span><span class="token2">(</span>$month<span class="token2">,</span>$day<span class="token2">)</span><span class="token2">{</span> <span class="token5">if</span><span class="token2">(</span>$month<span class="token"><</span><span class="token3">1</span><span class="token">||</span>$month<span class="token">></span><span class="token3">12</span><span class="token">||</span>$day<span class="token"><</span><span class="token3">1</span><span class="token">||</span>$day<span class="token">></span><span class="token3">31</span><span class="token2">)</span> <span class="token5">return</span> <span class="token3">false</span><span class="token2">;</span> $constellations<span class="token">=</span><span class="token1">array</span><span class="token2">(</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"20"</span><span class="token">=</span><span class="token">></span><span class="token4">"宝瓶座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"19"</span><span class="token">=</span><span class="token">></span><span class="token4">"双鱼座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"21"</span><span class="token">=</span><span class="token">></span><span class="token4">"白羊座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"20"</span><span class="token">=</span><span class="token">></span><span class="token4">"金牛座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"21"</span><span class="token">=</span><span class="token">></span><span class="token4">"双子座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"22"</span><span class="token">=</span><span class="token">></span><span class="token4">"巨蟹座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"23"</span><span class="token">=</span><span class="token">></span><span class="token4">"狮子座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"23"</span><span class="token">=</span><span class="token">></span><span class="token4">"处女座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"23"</span><span class="token">=</span><span class="token">></span><span class="token4">"天秤座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"24"</span><span class="token">=</span><span class="token">></span><span class="token4">"天蝎座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"22"</span><span class="token">=</span><span class="token">></span><span class="token4">"射手座"</span><span class="token2">)</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">"22"</span><span class="token">=</span><span class="token">></span><span class="token4">"摩羯座"</span><span class="token2">)</span> <span class="token2">)</span><span class="token2">;</span> <span class="token1">list</span><span class="token2">(</span>$constellation_start<span class="token2">,</span>$constellation_name<span class="token2">)</span><span class="token">=</span><span class="token1">each</span><span class="token2">(</span>$constellations<span class="token2">[</span><span class="token2">(</span>int<span class="token2">)</span>$month<span class="token">-</span><span class="token3">1</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span> <span class="token5">if</span><span class="token2">(</span>$day<span class="token"><</span>$constellation_start<span class="token2">)</span><span class="token2">{</span> <span class="token1">list</span><span class="token2">(</span>$constellation_start<span class="token2">,</span>$constellation_name<span class="token2">)</span><span class="token">=</span><span class="token1">each</span><span class="token2">(</span>$constellations<span class="token2">[</span><span class="token2">(</span>$month<span class="token">-</span><span class="token3">2</span><span class="token"><</span><span class="token3">0</span><span class="token2">)</span><span class="token">?</span>$month<span class="token">=</span><span class="token3">11</span><span class="token2">:</span>$month<span class="token">-</span><span class="token">=</span><span class="token3">2</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> <span class="token5">return</span> $constellation_name<span class="token2">;</span> <span class="token2">}</span> ``` ```