PHP操作期数,期号的常用方法

文章代码中参数说明:

$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);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章