Background :
I want to display the email address in a page, but i have to censored it first.
The method, as below :
input : yourname@domain.com
output : y******e@domain.com
So, here is the code
<?php
/******************************************************
* Class Name : CensoredEmail
* Scripted By : Mohammad Syafiuddin
* Website : http://www.udhien.net
* Email : udhien@udhien.net
* License : GPL (General Public License)
* Created Date : 2/12/2008
* Last Update : 2/12/2008
* Instruction :
* eg : echo CensoredEmail("you@domain.com", "*");
******************************************************/
function CensoredEmail($sEmail, $sMask = "*") {
$arrEmail = explode("@", $sEmail);
for ($i = 1; $i<= (strlen($arrEmail[0]) - 2);$i++) {
$sMaskInc .= $sMask;
}
return $arrEmail[0]{0}.substr_replace($arrEmail[0], $sMaskInc, 0, strlen($arrEmail[0])).$arrEmail[0]{strlen($arrEmail[0])-1}."@".$arrEmail[1];
}
?>
Usage Example :
<?php
echo CensoredEmail("yourname@domain.com", "*"); // output : y******e@domain.com
echo CensoredEmail("yourname@domain.com", "#"); // output: y######e@domain.com
?>
Download Censored Email - PHP Function (available in .txt format)
This function already posted in slash.web.id, PHPUG,
Posted on February 12th, 2008 by Mohammad Syafiuddin
Filed under: Web Programming Trackback URL
Tags: censored, email, php function
Prev Entry:Babak Baru Perang Megaportal: Kompas dan Okezone Goyang Detikcom?
Next Entry:slash.web.id - Indonesian IT Updates! website





























Leave a Reply