Hier meine PHP-Lösung, ohne jedes Mal die gesamte Vergleichs-Schleife durchlaufen zu muessen.
Die Schleifenvariante aus dem Original waere uebrigens effektiver, wenn man die Vergleiche entsprechend der relativen Häufigkeit von Zeichen anordnen wuerde.
Eddie
/* encrypts an e-mail address to hide mailto-links from address crawlers
*
* $eMail - address to encrypt
*
* returns the encrypted address
*/
function getEncodedMailToLink($eMail)
{
$eMail = strtolower($eMail);
$codes = array('e' => 'e',
'n' => 'n',
'i' => 'i',
's' => 's',
'r' => 'r',
'a' => 'a',
't' => 't',
'd' => 'd',
'u' => 'u',
'h' => 'h',
'g' => 'g',
'l' => 'l',
'c' => 'c',
'm' => 'm',
'w' => 'w',
'o' => 'o',
'b' => 'b',
'f' => 'f',
'z' => 'z',
'k' => 'k',
'v' => 'v',
'p' => 'p',
'j' => 'j',
'q' => 'q',
'x' => 'x',
'y' => 'y',
'0' => '0',
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
'9' => '9',
'&' => '&',
' ' => ' ',
'_' => '_',
'-' => '-',
'@' => '@',
'.' => '.',
);
$output = '';
for ($i = 0; $i < strlen($eMail); $i++)
{
$sign = substr($eMail, $i, 1);
$code = $codes[$sign];
if ($code != '')
{
$output .= $code;
}
else
{
$output .= $sign;
}
}
return $output;
}