<?php // Plug-in 84: Protect Email
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
$email = 'billgates@microsoft.com';
$pemail = PIPHP_ProtectEmail($email);
echo "My email address is $pemail";
function PIPHP_ProtectEmail($email)
{
// Plug-in 84: Protect Email
//
// This plug-in takes an email address and turns it into a
// clickable <a href='mailto:...' link using JavaScript
// to obfusacte the link when viewed using View | Source, or
// if the page is loaded by a spam email harvesting bot. On
// success it returns a string containing JavaScript code, or
// on failure it returns FALSE. It requires this argument:
//
// $email: An email address to protect
$t1 = strpos($email, '@');
$t2 = strpos($email, '.', $t1);
if (!$t1 || !$t2) return FALSE;
$e1 = substr($email, 0, $t1);
$e2 = substr($email, $t1, $t2 - $t1);
$e3 = substr($email, $t2);
return "<script>e1='$e1';e2='$e2';e3='$e3';document.write" .
"('<a href=\'mailto:' + e1 + e2 + e3 + '\'>' + e1 " .
"+ e2 + e3 + '</a>');</script>";
}
?>
插件说明:
插件接受一个Email地址,返回一段Javascript代码,他把这个地址在HTML页面上显示为一个超链接形式,而不是完整的Email地址。若操作成功则返回这个Javascript程序,若失败(如,这个Email地址无效),则返回false.他需要以下参数:
$email:需要处理的Email