PHP Function : Censored Email Address

3Mohammad Syafiuddin12th Feb 2008Web Programming, ,

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

3 Comments Comments Feed

  1. Jauhari (July 24, 2008, 6:04 am).

    Ini yang dicari cari mas ;)

  2. aprian (April 1, 2009, 10:19 pm).

    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.

  3. bali Florist (July 24, 2009, 11:21 pm).

    itu yang saya harapkan dari dulu.hhheeehhheee

Add a Comment

Captcha
Enter the letters you see above.

-->