插件84:保护Email

<?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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值