获取某个日期几个月后的这天
1、date:某个日期
2、between:几个月后(2代表一个月的这天,3代表2个月的这天)PS、2018-11-29,5:(就是11-29往后4个月的今天是多少号)
public function getNextMonthDays($date,$between){
$firstday = date('Y-m-01', strtotime($date));
$lastday = strtotime("$firstday +$between month -1 day");
$day_lastday = date('d', $lastday); //获取下个月份的最后一天
$day_benlastday = date('d', strtotime("$firstday +1 month -1 day")); //获取本月份的最后一天
//获取当天日期
$Same_day = date('d', strtotime($date));
//判断当天是否是最后一天 或 下月最后一天 等于 本月的最后一天
if($Same_day == $day_benlastday ||$day_lastday == $Same_day){
$day = $day_lastday;
}else{
$day = $Same_day;
}
$day = date('Y',$lastday).'-'.date('m',$lastday).'-'.$day;
return $day;
} 原生js实现复制功能
html代码
<input id="demoInput" value="hello world">
<button id="btn">点我复制</button>js代码
<script>
const btn = document.querySelector('#btn');
btn.addEventListener('click', () => {
const input = document.querySelector('#demoInput');
input.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
alert('复制成功');
}
})
</script> PHP安全
聚合快递
使用前你需要通过http://www.juhe.cn/docs/api/id/43 申请一个专用appkey
<?php
// +----------------------------------------------------------------------
// | JuhePHP [ NO ZUO NO DIE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Juhedata <info@juhe.cn-->
// +----------------------------------------------------------------------
//----------------------------------
// 聚合数据-快递查询API调用示例代码
//----------------------------------
header('Content-type:text/html;charset=utf-8');
$params = array(
'key' => '1168c59dc1d06c99c425e4503f8ba7c3', //您申请的快递appkey
'com' => 'zto', //快递公司编码,可以通过$exp->getComs()获取支持的公司列表
'no' => '264977774032' //快递编号
);
$exp = new exp($params['key']); //初始化类
$result = $exp->query($params['com'],$params['no']); //执行查询
//$a = $exp->getComs();
//var_dump($a);die;
if($result['error_code'] == 0){//查询成功
$list = $result['result']['list'];
print_r($list);
}else{
echo "获取失败,原因:".$result['reason'];
}
class exp{
private $appkey = false; //申请的快递查询APPKEY
private $queryUrl = 'http://v.juhe.cn/exp/index';
private $comUrl = 'http://v.juhe.cn/exp/com';
public function __construct($appkey){
$this->appkey = $appkey;
}
/**
* 返回支持的快递公司公司列表
* @return array
*/
public function getComs(){
$params = 'key='.$this->appkey;
$content = $this->juhecurl($this->comUrl,$params);
return $this->_returnArray($content);
}
public function query($com,$no){
$params = array(
'key' => $this->appkey,
'com' => $com,
'no' => $no
);
$content = $this->juhecurl($this->queryUrl,$params,1);
return $this->_returnArray($content);
}
/**
* 将JSON内容转为数据,并返回
* @param string $content [内容]
* @return array
*/
public function _returnArray($content){
return json_decode($content,true);
}
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @param int $ipost [是否采用POST形式]
* @return string
*/
public function juhecurl($url,$params=false,$ispost=0){
$httpInfo = array();
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($params){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
}else{
curl_setopt( $ch , CURLOPT_URL , $url);
}
}
$response = curl_exec( $ch );
if ($response === FALSE) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
curl_close( $ch );
return $response;
}
}
?> 