Encode Email Address using PHP

Posted: January 12, 2013 in PHP
  1. function encode_email($email=’info@domain.com’, $linkText=’Contact Us’, $attrs =’class=”emailencoder”‘ )
  2. {
  3.     // remplazar aroba y puntos
  4.     $email = str_replace(‘@’, ‘@’, $email);
  5.     $email = str_replace(‘.’, ‘.’, $email);
  6.     $email = str_split($email, 5);
  7.     $linkText = str_replace(‘@’, ‘@’, $linkText);
  8.     $linkText = str_replace(‘.’, ‘.’, $linkText);
  9.     $linkText = str_split($linkText, 5);
  10.     $part1 = ‘<a href=”ma’;
  11.     $part2 = ‘ilto:’;
  12.     $part3 = ‘” ‘. $attrs .’ >’;
  13.     $part4 = ‘</a>’;
  14.     $encoded = ‘<script type=”text/javascript”>’;
  15.     $encoded .= “document.write(‘$part1’);”;
  16.     $encoded .= “document.write(‘$part2’);”;
  17.     foreach($email as $e)
  18.     {
  19.             $encoded .= “document.write(‘$e’);”;
  20.     }
  21.     $encoded .= “document.write(‘$part3’);”;
  22.     foreach($linkText as $l)
  23.     {
  24.             $encoded .= “document.write(‘$l’);”;
  25.     }
  26.     $encoded .= “document.write(‘$part4’);”;
  27.     $encoded .= ‘</script>’;
  28.     return $encoded;
  29. }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s