屏蔽部分Email地址的smarty插件
来源:互联网 责任编辑:栏目编辑 发表时间:2013-07-01 13:01 点击:次
工作中用到的,觉得这样的显示工作,还是交给模板类比较合适。所以写了这样的一个插件。
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/ /**
* Smarty email_mask modifier plugin
*
* Type: modifier<br>
* Name: email_mask<br>
* Purpose: mask part of email<br>
* Input:<br>
* - string: input email
* - part: mask part [default '60'] unit: percent
* - position: mask position [default 'center'] (left, center, right)
* - maskString: mask string [default '*']
*
* @author wendaming <wendaming at comsenz dot com>
* @param string
* @param integer
* @param string
* @param string
* @return string|void
*/ function smarty_modifier_email_mask($string, $maskPart = 60, $position = 'center', $maskString = '*') {
$emailName = substr($string, 0, strpos($string, '@'));
$emailLen = strlen($emailName);
$maskNum = floor($emailLen * $maskPart / 100);
$maskName = ''; if ($position == 'center') {
$beginMask = floor(($emailLen - $maskNum) / 2);
} elseif ($position == 'left') {
$beginMask = 0;
} else {
$beginMask = $emailLen - $maskNum;
}
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/ /**
* Smarty email_mask modifier plugin
*
* Type: modifier<br>
* Name: email_mask<br>
* Purpose: mask part of email<br>
* Input:<br>
* - string: input email
* - part: mask part [default '60'] unit: percent
* - position: mask position [default 'center'] (left, center, right)
* - maskString: mask string [default '*']
*
* @author wendaming <wendaming at comsenz dot com>
* @param string
* @param integer
* @param string
* @param string
* @return string|void
*/ function smarty_modifier_email_mask($string, $maskPart = 60, $position = 'center', $maskString = '*') {
$emailName = substr($string, 0, strpos($string, '@'));
$emailLen = strlen($emailName);
$maskNum = floor($emailLen * $maskPart / 100);
$maskName = ''; if ($position == 'center') {
$beginMask = floor(($emailLen - $maskNum) / 2);
} elseif ($position == 'left') {
$beginMask = 0;
} else {
$beginMask = $emailLen - $maskNum;
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>