ctms/vendor/fmsoft/function/fm.func.php
2025-04-10 23:19:13 +08:00

136 lines
3.4 KiB
PHP
Executable File

<?php
/**
* @author Fm453
* @remark Api站公用函数
*/
defined('HI_FM') or exit("Access Denied");
function getMillisecond(){
//获取毫秒级时间
list($t1,$t2) = explode(' ',microtime());
return (float)sprintf('%.f',(floatval($t1) + floatval($t2))*1000);
}
//手机号掩码
function mobile_mask($mobile) {
return substr($mobile, 0, 3) . '****' . substr($mobile, 7);
}
//银行卡号加空格隔断
function bankcard_space($cardnumber){
$card ='';
for($i=0; $i<5; $i++){
$card = $card. substr($cardnumber,4*$i,4). ' ';
}
return $card;
}
//PHP stdClass Object转array
if(!function_exists('fm_object2array')){
function fm_object2array($array) {
if(is_object($array)) {
$array = (array)$array;
}
if(is_array($array)) {
foreach($array as $key=> &$value) {
if(is_object($value)) {
$value = (array)$value;
}
if(is_array($value)){
foreach($value as $k => &$v){
$value[$k] = fm_object2array($v);
}
}
$array[$key] = $value;
}
}
return $array;
}
}
function iserializer($value) {
return serialize($value);
}
function iunserializer($value) {
if (empty($value)) {
return '';
}
if (!is_serialized($value)) {
return $value;
}
$result = unserialize($value);
if ($result === false) {
$temp = preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($matchs){
return 's:'.strlen($matchs[2]).':"'.$matchs[2].'";';
}, $value);
return unserialize($temp);
}
return $result;
}
function is_serialized($data, $strict = true) {
if (!is_string($data)) {
return false;
}
$data = trim($data);
if ('N;' == $data) {
return true;
}
if (strlen($data) < 4) {
return false;
}
if (':' !== $data[1]) {
return false;
}
if ($strict) {
$lastc = substr($data, -1);
if (';' !== $lastc && '}' !== $lastc) {
return false;
}
} else {
$semicolon = strpos($data, ';');
$brace = strpos($data, '}');
if (false === $semicolon && false === $brace)
return false;
if (false !== $semicolon && $semicolon < 3)
return false;
if (false !== $brace && $brace < 4)
return false;
}
$token = $data[0];
switch ($token) {
case 's' :
if ($strict) {
if ('"' !== substr($data, -2, 1)) {
return false;
}
} elseif (false === strpos($data, '"')) {
return false;
}
case 'a' :
case 'O' :
return (bool)preg_match("/^{$token}:[0-9]+:/s", $data);
case 'b' :
case 'i' :
case 'd' :
$end = $strict ? '$' : '';
return (bool)preg_match("/^{$token}:[0-9.E-]+;$end/", $data);
}
return false;
}
//生成不重复的随机字符串
function randchars($len)
{
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$string=time();
for(;$len>=1;$len--)
{
$position=rand()%strlen($chars);
$position2=rand()%strlen($string);
$string=substr_replace($string,substr($chars,$position,1),$position2,0);
}
return $string;
}