/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * 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 = '') { $encodedDomain = ''; $encodedName = ''; $encodedDisplay = ''; { } { } { } $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; }