-
PHP获取指定月份的起止时间戳
?php/***获取指定月份的时间戳*@param$dateY-m*/functionget_month_begin_end($date){//$date=2018-11;$data[begin_time]=strtotime($date);//指定月份月初时间戳$data[end_time]=mktime(23,59,59,date(m,strtotime($date))+1,00);//指定月份月末时间戳return$data;}? …
-
PHP获取当前周的每天的起始时间戳函数
?phpfunctiongetDay(){$timestr=time();//当前时间戳$now_day=date(w,$timestr);//当前是周几//获取周一$monday_str=$timestr-($now_day-1)*60*60*24;$monday=date(Y-m-d,$monday_str);//获取周日$sunday_str=$timestr+(7-$now_day)*60*60*24;$sunday=date(Y-m-d,$sunday_str);for($i=0;$i7;$i++){$arr[$i][start]=strtotime(date(Y-m-d,strtotime($monday.+.$i.day)));$arr[$i][end]=strtotime(date(Y-m-d,strtotime($monday.+.$i.day)).24:00:00);}return$arr;}? …
-
PHP随机获取国内IP地址的方法
?php//随机IP地址//$randip=rand(1,254)...rand(1,254)...rand(1,254)...rand(1,254);//echo$randip;//随机国内IP地址$iprand=array(array(607649792,608174079),/*36.56.0.0-36.63.255.255*/array(1038614528,1039007743),/*61.232.0.0-61.237.255.255*/array(1783627776,1784676351),/*106.80.0.0-106.95.255.255*/array(2035023872,2035154943),/*121.76.0.0-121.77.255.255*/array(2078801920,2079064063),/*123.232.0.0-123.235.255.255*/array(-1950089216,-1948778497),/*139.196.0.0-139.215.255.255*/array(-142553907…
-
PHP获取今日、昨日、上周、本周、上月、本月的起始时间戳
?php//今日开始时间戳和结束时间戳$beginToday=mktime(0,0,0,date(m),date(d),date(Y));$endToday=mktime(0,0,0,date(m),date(d)+1,date(Y))-1;//昨日起始时间戳和结束时间戳$beginYesterday=mktime(0,0,0,date(m),date(d)-1,date(Y));$endYesterday=mktime(0,0,0,date(m),date(d),date(Y))-1;//本周起始时间戳和结束时间戳$startTime=mktime(0,0,0,date(m),date(d)-date(w)+1,date(y));$endTime=mktime(23,59,59,date(m),date(d)-date(w)+7,date(y));//上周起始时间戳和结束时间戳$…
-
PHP获取指定年份的每个月的起始时间
?php/***@paramyear年份*/functiongetMonthByDate($year){//$year=2019;$yeararr=[];$month=[];for($i=1;$i=12;$i++){$yeararr[$i]=$year.-.$i;}foreach($yeararras$key=$value){$timestamp=strtotime($value);$start_time=date(Y-m-100:00:00,$timestamp);$mdays=date(t,$timestamp);$end_time=date(Y-m-.$mdays.23:59:59,$timestamp);$month[$key][start_time]=strtotime($start_time);$month[$key][end_time]=strtotime($end_time);}return$month;}? …
-
PHP中使用正则表达式来检测字符中是否含有大写字母
使用preg_match()函数配合正则表达式来检测是否含有大写字母 preg_match 函数用于执行一个正则表达式pattern匹配,会返回 pattern 的匹配次数(0或1)。0代表没有匹配,1代表有匹配。 用到的正则为:/[A-Z]/,用于查找大写字母 ?phpfunctionis_bigstr($str){if(preg_match(/[A-Z]/,$str)){echo有大写字母!br;}else{echo没有大写字母!br;}}is_bigstr(hello);is_bigstr(Hello);? …
-
PHP通过时间戳获取某个日期段内的周几获取对应的日期 开始日期 结束日期
?php/***@paramdata日期array(start_date,end_data)*/functiongetDateByWeek($data){$start_date=strtotime($data[start_date]);$end_date=strtotime($data[end_date]);$days=($end_date-$start_date)/86400;$weekArr=array(周日,周一,周二,周三,周四,周五,周六);$newDate=array();//组建数组格式$dataWeek[日期]=星期for($i=0;$i$days;$i++){$num_week=date(w,$start_date+($i*86400));$dateWeek[date(Y-m-d,$start_date+($i*86400))]=$weekArr[$num_week];}//查找两个数组的交集,即获取提交的…
-
PHP遍历数组效率最高的几种方法
PHP中遍历数组有三种常用的方法: 一、使用for语句循环遍历数组; 二、使用foreach语句遍历数组; 三、联合使用list()、each()和while循环遍历数组。 这三种方法中效率最高的是使用foreach语句遍历数组。从PHP4开始就引入了foreach结构,是PHP中专门为遍历数组而设计的语句,推荐大家使用。先分别介绍这几种方法。 一、使用for语句循环遍历数组 值得大家注意的是使用for语句循环遍历数…
-
PHP获取周的开始时间和结束时间戳函数
1、根据指定时间获取所在周的起始时间和结束时间 ?php/***@paramdata日期*/functionget_weekinfo_by_time($date){$idx=strftime(%u,strtotime($date));$mon_idx=$idx-1;$sun_idx=$idx-7;returnarray(week_start_day=strftime(%Y-%m-%d,strtotime($date)-$mon_idx*86400),week_end_day=strftime(%Y-%m-%d,strtotime($date)-$sun_idx*86400),);}? 2、通过时间戳获取某周的开始时间和结束时间 ?php/***@paramtime时间*@paramfirst表示每周星期一为开始日期0表示每周日为开始…
-
PHP判断访问者手机端还是电脑端的函数
?phpfunctionMobile(){if(isset($_SERVER[HTTP_USER_AGENT])){$client=array(mobile,android,iPhone,iPod,ios,wap);if(preg_match(/(.implode(|,$client).)/i,strtolower($_SERVER[HTTP_USER_AGENT]))){returntrue;}}returnfalse;}if(Mobile()){echo手机端;}else{echo电脑端;}? …