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,

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Y!GG
  • Bloglines
  • blogmarks
  • Google Bookmarks
  • Ma.gnolia
  • Technorati
  • YahooMyWeb
  • blinkbits
  • BlinkList
  • Blue Dot
  • Book.mark.hu
  • co.mments
  • De.lirio.us
  • Furl
  • Linkarena
  • Linkter
  • MyShare
  • Netscape
  • NewsVine
  • Simpy
  • Slashdot
  • SphereIt
  • Spurl
  • Taggly

Leave a Reply

Captcha
Enter the letters you see above.