Another little modification. At this time the snippet shows the "real" email address as mail link text. With the little mod it shows whatever you want.
Usage:
[[AntispamEmail? &mailadr=`[email protected]` &coding=`anything`]]
with "anything" as unicode / atdot / both / custom text
E.g. if you set the &coding as "say hello to me" the mail link text will show this.
# written by Frank Burian, modified by Rainer Schlegel
#
# displays email address as you want (see parameter "coding")
# the email link itself is md5 coded with "mailto" as unicode (otherwise rendering fails)
#
# parameters:
# mailadr - email address you wish to scramble
# coding (optional, if isn't present the default is "unicode") - output of visible email link text:
# - "unicode" -> email address output as unicode (browser renders it as visible text, spambot may fail)
# - "atdot" -> email address output as "test [at] domain [dot] tld"
# - "both" -> both :-)
# - other text, for instance "contact", "say hello to me" ;-)
$mailadr = isset($mailadr)? $mailadr : '[email protected]';
$coding = isset($coding)? $coding : 'unicode';
function no_spam($spamprotect) {
$str = "";
$a = unpack("C*", $spamprotect);
foreach ($a as $b)
$str .= sprintf("%%%X", $b);
return $str;
}
function no_spam2($address,$coding)
{
$address=trim($address);
$output="";
switch($coding)
{
case 'unicode':
for ($i=0;$i<strlen($address);$i++) $output.=str_replace(substr($address,$i,1),"&#".ord(substr($address,$i,1)).";",substr($address,$i,1));
break;
case 'atdot':
$output=preg_replace('#(.*)\@(.*)\.(.*)#','\\1 [at] \\2 [dot] \\3',$address);
break;
case 'both':
$address=preg_replace('#(.*)\@(.*)\.(.*)#','\\1 [at] \\2 [dot] \\3',$address);
for ($i=0;$i<strlen($address);$i++) $output.=str_replace(substr($address,$i,1),"&#".ord(substr($address,$i,1)).";",substr($address,$i,1));
break;
default:
for ($i=0;$i<strlen($coding);$i++) $output.=str_replace(substr($coding,$i,1),"&#".ord(substr($coding,$i,1)).";",substr($coding,$i,1));
break;
}
return $output;
}
$spamprotect = no_spam($mailadr);
$spamprotect2 = no_spam2($mailadr,$coding);
echo "<a href='mailto:".$spamprotect."'>".$spamprotect2."</a>";
greetings, Rainer