PHP Function : Censored Email Address
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,




























Ini yang dicari cari mas
Dhien gmana kalo pake sedikit bantuan regex buat nyari text yg disensor. Iseng2 nyoba regexnya coba : (?<=[a-zA-Z])[a-zA-Z].+(?=[a-zA-Z]@) . Misal yourname@domain.com, regex itu bakal capture: ournam . Dapet itu kan tinggal replace aja jadinya. Sekedar ide sih, males mikir php nya.. hahahaha.
itu yang saya harapkan dari dulu.hhheeehhheee