文章代碼中參數說明:
$code ==============> 別名
$expect ==============> 期號
$opencode ==============> 號碼
一、號碼補0
比如“1,3,5,7,9”,轉換成“01,03,05,07,09”
//號碼補0
if($code=="azxy20"){
$hm=explode(",",$opencode);
for($i=0;$i<count($hm);$i++){
$hm[$i]=BuLing($hm[$i]);
}
//數組轉換字符串
$opencode=implode(",",$hm);
}
/*
數字補0函數,當數字小於10的時候在前面自動補0
*/
function BuLing ( $num ) {
if ( $num<10 ) {
$num = '0'.$num;
}
return $num;
}
二、期號補0
比如2019063015,轉換成20190630015
//期號補0
if(strpos($code,'ssc') !== false||strpos($code,'k3') !== false||strpos($code,'11x5') !== false||strpos($code,'klsf') !== false){
if($code!="gxklsf"){//廣西快樂十分比較特別
if(substr($expect,0,4)==date("Y")){
$nyr=substr($expect,0,8);
$qishu=substr($expect,8);
if(strlen($qishu)<3){
$expect=$nyr."0".$qishu;
}
}
}
}
三、期號補全年份
比如191215030,轉換成20191215030
//期號補全年份
$arr=array('pl3','pl5','dlt','qxc');
if(in_array($code,$arr)||strpos($code,'k3') !== false||strpos($code,'11x5') !== false||strpos($code,'klsf') !== false){
//北京快3比較特別
if($code!="bjk3"){
$prefix=substr($expect,0,4);
if($prefix!=date("Y")){
$expect=substr(date("Y"),0,2).$expect;
}
}
}
四、刪除號碼多出一個的問題
$shuzu=array('bjkl8','jisukl8','azxy20','twbingo','twbg28');
if(in_array($code,$shuzu)){
$arr=explode(",",$opencode);
if(count($arr)>20){
//去掉數組的最後一個元素
array_pop($arr);
//數組轉換字符串
$opencode=implode(",",$arr);
}
}
五、去掉期號前的0
比如“01,03,05,07,09”,轉換成“1,3,5,7,9”
if($code=="bjpk10"){
$hm=explode(",",$opencode);
for($i=0;$i<count($hm);$i++){
if($hm[$i]<10){
$hm[$i]=preg_replace('/^0+/','',$hm[$i]);
}
}
//數組轉換字符串
$opencode=implode(",",$hm);
}