Skip to content
Permalink
Browse files

filterEmoji 缺少函数

  • Loading branch information...
sugar1569 committed Jul 16, 2019
1 parent 2cdcd06 commit b4d287adc210f50c56ebaa5f079b2e98f9404c2a
Showing with 49 additions and 0 deletions.
  1. +49 −0 application/common.php
@@ -57,4 +57,53 @@ function makePathToUrl($path,$type = 2)
return trim(str_replace(DS, '/',UPLOAD_PATH.$path),'.');
}else return '';
}
// 过滤掉emoji表情
function filterEmoji($str)
{
$str = preg_replace_callback( //执行一个正则表达式搜索并且使用一个回调进行替换
'/./u',
function (array $match) {
return strlen($match[0]) >= 4 ? '' : $match[0];
},
$str);
return $str;
}
//可逆加密
function encrypt($data, $key) {
$prep_code = serialize($data);
$block = mcrypt_get_block_size('des', 'ecb');
if (($pad = $block - (strlen($prep_code) % $block)) < $block) {
$prep_code .= str_repeat(chr($pad), $pad);
}
$encrypt = mcrypt_encrypt(MCRYPT_DES, $key, $prep_code, MCRYPT_MODE_ECB);
return base64_encode($encrypt);
}
//可逆解密
function decrypt($str, $key) {
$str = base64_decode($str);
$str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
$block = mcrypt_get_block_size('des', 'ecb');
$pad = ord($str[($len = strlen($str)) - 1]);
if ($pad && $pad < $block && preg_match('/' . chr($pad) . '{' . $pad . '}$/', $str)) {
$str = substr($str, 0, strlen($str) - $pad);
}
return unserialize($str);
}
//替换一部分字符
/**
* @param $string 需要替换的字符串
* @param $start 开始的保留几位
* @param $end 最后保留几位
* @return string
*/
function strReplace($string,$start,$end)
{
$strlen = mb_strlen($string, 'UTF-8');//获取字符串长度
$firstStr = mb_substr($string, 0, $start,'UTF-8');//获取第一位
$lastStr = mb_substr($string, -1, $end, 'UTF-8');//获取最后一位
return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($string, 'utf-8') -1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
}

0 comments on commit b4d287a

Please sign in to comment.
You can’t perform that action at this time.