杂项
一、laravel相关
\DB::connection()->enableQueryLog(); // 开启SQL监控 # SQL语句 $queries = \DB::getQueryLog(); // 查询监控之中所有SQL语句
二、html
/*******视频播放代码*********/ <object id="MediaPlayer" classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="800" height="600" standby="Loading Windows Media Player components…" type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"> <param name="FileName" value="视频地址"> <param name="AutoStart" value="true"> <param name="ShowControls" value="true"> <param name="BufferingTime" value="2"> <param name="ShowStatusBar" value="true"> <param name="AutoSize" value="true"> <param name="InvokeURLs" value="false"> <param name="AnimationatStart" value="1"> <param name="TransparentatStart" value="1"> <param name="Loop" value="1"> <embed type="application/x-mplayer2" src="视频地址" name="MediaPlayer" autostart="1" showstatusbar="1" showdisplay="1" showcontrols="1" loop="0" videoborder3d="0" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" width="800" height="600"></embed> </object> /*******视频播放代码*********/
三、php
public function sign_di(){
$prize_arr = array(
'0' => array('id'=>1,'prize'=>'5','v'=>1),
'1' => array('id'=>2,'prize'=>'4','v'=>10),
'2' => array('id'=>3,'prize'=>'3','v'=>20),
'3' => array('id'=>4,'prize'=>'2','v'=>50),
'4' => array('id'=>5,'prize'=>'1','v'=>200),
'5' => array('id'=>6,'prize'=>'0','v'=>150),
);
foreach ($prize_arr as $key => $val) {
$arr[$val['id']] = $val['v'];
}
$rid = $this->get_rand($arr); //根据概率获取奖项id
$res = $prize_arr[$rid-1]['prize'].'钻石'; //中奖项
// unset($prize_arr[$rid-1]); //将中奖项从数组中剔除,剩下未中奖项
// shuffle($prize_arr); //打乱数组顺序
// for($i=0;$i<count($prize_arr);$i++){
// $pr[] = $prize_arr[$i]['prize'];
// }
// $res['no'] = $pr;
dd($res);
}
/**
预算概率
**/
function get_rand($proArr) {
$result = '';
//概率数组的总概率精度
$proSum = array_sum($proArr);
//概率数组循环
foreach ($proArr as $key => $proCur) {
$randNum = mt_rand(1, $proSum);
if ($randNum <= $proCur) {
$result = $key;
break;
} else {
$proSum -= $proCur;
}
}
unset ($proArr);
return $result;
}
获取本月日期:
function getMonth($date){
$firstday = date("Y-m-01",strtotime($date));
$lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day"));
return array($firstday,$lastday);
}
获取上月日期:
function getlastMonthDays($date){
$timestamp=strtotime($date);
$firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)-1).'-01'));
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
return array($firstday,$lastday);
}
获取下月日期:
function getNextMonthDays($date){
$timestamp=strtotime($date);
$arr=getdate($timestamp);
if($arr['mon'] == 12){
$year=$arr['year'] +1;
$month=$arr['mon'] -11;
$firstday=$year.'-0'.$month.'-01';
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
}else{
$firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)+1).'-01'));
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
}
return array($firstday,$lastday);
}
<?php$htmlStrings = view('viewPath')->__toString();
换了ob_star技术,但是在blade模板的第一行加入ob_star(),在页面最后一行加上ob_get_contents()等代码来获取页面流,写入一个文件。结果是成功把生成的页面写入html文件,但是浏览器中看到的页面是空白的。
//获取数组制定值
$transport = array('foot'=>'foot', 'bike1'=>'bike', 'car1'=>'car', 'plane1'=>'plane'); $mode = current($transport); // $mode = 'foot'; $mode = next($transport); // $mode = 'bike'; $mode = current($transport); // $mode = 'bike'; $mode = prev($transport); // $mode = 'foot'; $mode = end($transport); // $mode = 'plane'; $mode = current($transport); // $mode = 'plane';
<?php
/**判断是否为MD5
*/
function is_md5($password) {
return preg_match("/^[a-f0-9]{32}$/", $password);
}
<?php //PHP计算两个时间差的方法$startdate="2010-12-11 11:40:00"; $enddate="2012-12-12 11:45:09"; $date=floor((strtotime($enddate)-strtotime($startdate))/86400); $hour=floor((strtotime($enddate)-strtotime($startdate))%86400/3600); $minute=floor((strtotime($enddate)-strtotime($startdate))%86400/60); $second=floor((strtotime($enddate)-strtotime($startdate))%86400%60); echo$date."天<br>"; echo$hour."小时<br>"; echo$minute."分钟<br>"; echo$second."秒<br>"; ?>
四、js
//数组乱序函数
function shuffle(inputArr) {
var valArr = [], k = '';
for (k in inputArr) { // 获取密钥和值数组
if (inputArr.hasOwnProperty(k)) {
valArr.push(inputArr[k]);
}
}
valArr.sort(function () {
return 0.5 - Math.random();
});
return valArr;
}
/**
* 随机数
* lowerValue 最小值
* upperValue 最大值
*/
function selectFrom(lowerValue, upperValue) {
//取值范围总数
var choices = upperValue - lowerValue + 1;
return Math.floor(Math.random() * choices + lowerValue);
}
js 概率计算
functionprizeRand(oArr){
var sum = 0; // 总和var rand = 0; // 每次循环产生的随机数var result = 0; // 返回的对象的keyconsole.log(oArr);
// 计算总和for (var i in oArr) {
sum += oArr[i][0];
}
// 思路就是如果设置的数落在随机数内,则返回,否则减去本次的数for (var i in oArr) {
rand = Math.floor(Math.random()*sum + 1);
if (oArr[i][0] >= rand) {
result = oArr[i][0];
break;
} else {
sum -= oArr[i][0];
}
}
return result;
}
var oArr = {'5':[5, 'Mac'], '3':[15, 'iPhone'], '2':[30, 'iPad'], '1':[50, 'iWatch']};
console.log(prizeRand(oArr));
// $arr = DB::table('sign_diamonds')->get();
// $prize_arr[] = array();
// foreach ($arr as $key=>$val) {
// $prize_arr[$key] = array("id"=>$val->id,"prize"=>$val->prize,"v"=>$val->v);
// }
select substring_index(substring_index(a.signboard_skills,'|',b.help_topic_id+1),'|',-1) `number`,count(*) `count` from game_racebegin a
join help_topic b on b.help_topic_id <![CDATA[ < ]]> (length(a.signboard_skills) - length(replace(a.signboard_skills,'|',''))+1)
join (select role_id , MAX(date_time) date_time from game_racebegin
(转载请注明花儿为何那样红博客)

浙公网安备 33010602011771号