php获取毫秒时间戳
PHP获取毫秒时间戳
<?php /** * 返回当前的毫秒时间戳 * @return string */ function msectime() { list($tmp1, $tmp2) = explode(' ', microtime()); return sprintf('%.0f', (floatval($tmp1) + floatval($tmp2)) * 1000); }
/**
* 格式化数据化手机号码
* @param $mobile
* @return string
*/
function format_mobile($mobile)
{
return substr($mobile, 0, 5) . "****" . substr($mobile, 9, 2);
}
/**
* 数组转xml
* @param $arr
* @param string $root
* @return string
*/
function arrayToXml($arr, $root = "root")
{
$xml = "<" . $root . ">";
foreach ($arr as $key => $val) {
if (is_array($val)) {
$xml .= "<" . $key . ">" . arrayToXml($val, $root) . "</" . $key . ">";
} else {
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
}
}
$xml .= "</" . $root . ">";
return $xml;
}
/**
* xml转数组
* @param $xml
* @return mixed
*/
function xmlToArray($xml)
{
libxml_disable_entity_loader(true);
$values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $values;
}
/**
* 格式化银行卡号,前四位和最后显示原样的,其他隐藏
* @param $cardNo
* @return string
*/
function bankCardNoFormat($cardNo)
{
$n = strlen($cardNo);
//判断尾部几位显示原型
if ($n % 4 == 0) {
$j = 4;
} else {
$j = $n % 4;
}
$str = "";
for ($i = 0; $i < $n; $i++) {
if ($i < 4 || $i > $n - $j - 1) {
$str .= $cardNo[$i];
} else {
$str .= "*";
}
if ($i % 4 == 3) {
$str .= " ";
}
}
return $str;
}
/***
* 判断是否json
* @param $str
* @return bool
*/
function isjson($str)
{
return is_null(json_decode($str)) ? false : true;
}
/**
* 判断是否手机号
* @param $mobile
* @return bool
*/
function isMobile($mobile = '')
{
if (preg_match("/^1[3456789]{1}\d{9}$/", $mobile)) {
return true;
} else {
return false;
}
}
/**
* 验证是否邮箱
* @param $email
* @return bool
*/
function isEmail($email)
{
$pattern = '/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2})?)$/i';
if (preg_match($pattern, $email)) {
return true;
} else {
return false;
}
}
/***
* 导出时字符串太长不显示时,处理
*/
function convertString($value = '')
{
return $value . "\t";
}
/**
* 自定义URL
*/
function _url($url,$arr,$isNotHtml=true,$domain = false){
$url = url($url,$arr,$isNotHtml,$domain);
if ($domain == true){
$url = str_replace($_SERVER['SCRIPT_NAME'],'',$url);
}
return str_replace(array('%E3%80%90','%E3%80%91','%5B%5B','%5D%5D'),array("'+","+'",'{{','}}'),$url);
}
/**
* 获取请求接口token
* @return string
*/
function get_token(){
$token = md5(date('Y/m/d').'/d964963af857e7d7d2ea9891a27be0c7');
return $token;
}
/**
* 获取唯一token
* @return string
*/
public function uniqidToken(){
$token = md5(date('Y/m/d').'/d964963af857e7d7d2ea9891a27be0c7'.uniqid());
return $token;
}
php内置函数uniqid()
uniqid()函数基于以微妙的当前时间,生成一个唯一的ID。
echo uniqid();
echo uniqid();
echo uniqid();
OUTPUT:
5a4b62dd4aeea
5a4b62dd4aff7
5a4b62dd4b069