首页 > 代码库 > php随笔

php随笔

time to string

function magtime($inputs,$to = ‘2str‘){    if($to==‘2str‘&&!(is_numeric($inputs))&&!($to==‘2num‘&&preg_match("/^[a-z]{2,10}$/",$inputs))) return false;    $skeys = $akeys = array(‘f‘,‘a‘,‘d‘,‘e‘,‘c‘,‘y‘,‘z‘,‘t‘,‘k‘,‘g‘);    sort($skeys);    $inputs = str_split($inputs);    if($to==‘2str‘){        $ft_key = array_rand($akeys);        $keys = $ft_key%2==0 ? $skeys : $akeys;        $rs = ‘‘;        foreach($inputs as $input){            $rs .= $keys[$input];        }        $rs .= $akeys[$ft_key];    }elseif($to==‘2num‘){        $footer = array_pop($inputs);        $ft_key = array_search($footer,$akeys);        if($ft_key===false) return false;        $keys = $ft_key%2==0 ? $skeys : $akeys;        $keys = array_flip($keys);        $rs = ‘‘;        foreach($inputs as $input){            $rs .= $keys[$input];        }    }    return $rs;}$time = ‘1416896158‘;echo $time;echo "<br>";$str = magtime($time);echo $str;echo "<br>";$num = magtime($str,‘2num‘);echo $num;echo "<br>";

 

php随笔