Home php教程 php手册 屏蔽Email地址的smarty插件

屏蔽Email地址的smarty插件

Jun 21, 2016 am 08:57 AM

作中用到的,觉得这样的显示工作,还是交给模板类比较合适。

工作中用到的,觉得这样的显示工作,还是交给模板类比较合适。所以写了这样的一个插件。

 

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty email_mask modifier plugin
 *
 * Type:     modifier

 * Name:     email_mask

 * Purpose:  mask part of email

 * Input:

 *         - string: input email
 *         - part: mask part [default '60'] unit: percent
 *         - position: mask position [default 'center'] (left, center, right)
 *         - maskString: mask string [default '*']
 *
 * @author  wendaming
 * @param string
 * @param integer
 * @param string
 * @param string
 * @return stringvoid
 */

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;
    }

    $count = 0;
    for ($i = 0; $i         if ($i >= $beginMask && $count             $maskName .= $maskString;
            ++ $count;
        } else {
            $maskName .= $emailName{$i};
        }
    }

    return str_replace($emailName . '@', $maskName . '@', $string);
}



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)