private function encodeEmailAddress($addr)
{
$addr = "mailto:" . $addr;
$chars = preg_split('/(?<!^)(?!$)/', $addr);
$seed = (int) abs(crc32($addr) / strlen($addr));
# Deterministic seed.
foreach ($chars as $key => $char) {
$ord = ord($char);
# Ignore non-ascii chars.
if ($ord < 128) {
$r = $seed * (1 + $key) % 100;
# Pseudo-random function.
# roughly 10% raw, 45% hex, 45% dec
# '@' *must* be encoded. I insist.
if ($r > 90 && '@' != $char) {
/* do nothing */
} elseif ($r < 45) {
$chars[$key] = '&#x' . dechex($ord) . ';';
} else {
$chars[$key] = '&#' . $ord . ';';
}
}
}
$addr = implode('', $chars);
$text = implode('', array_slice($chars, 7));
# text without `mailto:`
return [$addr, $text];
}