Smarty Plugin for shielding email address

Source: Internet
Author: User
Tags count modifier
For the use of, think such display work, or to the template class is more appropriate. Work to use, feel such a display work, or to the template class is more appropriate.   So write a plugin like this. <?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 '] 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 Stringvoid
* * Function Smarty_modifier_email_mask ($string, $maskPart =, $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;
} $count = 0;
for ($i = 0; $i < $emailLen; + + $i) {
if ($i >= $beginMask && $count < $maskNum) {
$maskName. = $maskString;
+ + $count;
} else {
$maskName. = $emailName {$i};
}
Return Str_replace ($emailName. ' @ ', $maskName. ' @ ', $string);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.