Revision: 1151
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 19, 2006 04:38 by mikeejay
Initial Code
/** * Description: E-Mail encoder to reduce spam. * * @author Micke Johansson * * $mail. The e-mail address to encode. * $isLink. Set to true to create a link. * $display. What will be displayed in the browser. If omitted it will display the e-mail address. * * @param string $mail * @param bool $isLink * @param string $display * @return string Encoded e-mail or e-mail link */ function EncodeMail($mail, $isLink = false, $display = '') { $domain = substr($mail,strpos($mail, '@')+1); $name = substr($mail,0, strpos($mail, '@')); $encodedDomain = ''; $encodedName = ''; $encodedDisplay = ''; for ($i=0; $i < strlen($domain); $i++) { $encodedDomain .= '&#'.ord(substr($domain,$i)).';'; } for ($i=0; $i < strlen($name); $i++) { $encodedName .= '&#'.ord(substr($name,$i)).';'; } for ($i=0; $i < strlen($display); $i++) { $encodedDisplay .= '&#'.ord(substr($display,$i)).';'; } $script = "<script type=\"text/javascript\">"; $script .= "d=\"".$encodedDomain."\";"; $script .= "n=\"".$encodedName."\";"; if ($isLink) { if ($display == '') $script .= "document.write('<a href=\"mailto:'+n+'@'+d+'\">'+n+'@'+d+'</a>');"; else $script .= "document.write('<a href=\"mailto:'+n+'@'+d+'\">".$encodedDisplay."</a>');"; } else { $script .= "document.write(n+'@'+d);"; } $script .= "</script>"; return $script; }
Initial URL
Initial Description
Initial Title
E-mail encoder to reduce spam
Initial Tags
php, mail
Initial Language
PHP