Web Content: Protecting E-mail Address


Web Content Tips - Part 3: Because any spam out of there, we need protect our public email address from being captured by and e-mail address harvester. We ever talk about protecting email at here. At that post, we use JavaScript. In this post, we use different approach.

In this post, we try to modify text. Example, we want to display "me_you@sub.mysite.com". We will display become "me underscore you at sub dot mysite dot com". Look the code:

<?php
function protectEmail($email){
  $search = array(".", "@", "_", "-");
  $replace = array(" dot ", " at ", " underscore ", " dash ");
  
  return str_replace($search, $replace, $email);
}

$email = "me_you@sub.mysite.php";

echo protectEmail($email);
// result: me underscore you at sub dot mysite dot php
?>



Bookmark and Share Tag: web content, email Category: PHP Basic Post : April 27th 2008 Read: 2,535

advertisements


blog comments powered by Disqus