>  기사  >  백엔드 개발  >  PHP编码电子邮件地址,防止被垃圾邮件程序收集

PHP编码电子邮件地址,防止被垃圾邮件程序收集

WBOY
WBOY원래의
2016-06-20 13:03:051506검색

PHP编码电子邮件地址

以下代码可以将任何电子邮件地址编码为 html 字符实体,以防止被垃圾邮件程序收集。

 

function encode_email($email='info@domain.com', $linkText='Contact Us', $attrs ='class="emailencoder"' )  
{  
    // remplazar aroba y puntos  
    $email = str_replace('@', '@', $email);  
    $email = str_replace('.', '.', $email);  
    $email = str_split($email, 5);    
  
    $linkText = str_replace('@', '@', $linkText);  
    $linkText = str_replace('.', '.', $linkText);  
    $linkText = str_split($linkText, 5);    
  
    $part1 = '<a href="ma';%20%20%0A%20%20%20%20%24part2%20=%20'ilto:';%20%20%0A%20%20%20%20%24part3%20=%20'" .>';  
    $part4 = '</a>';    
  
    $encoded = '<script type="text/javascript">&#39;;  
    $encoded .= "document.write(&#39;$part1&#39;);";  
    $encoded .= "document.write(&#39;$part2&#39;);";  
    foreach($email as $e)  
    {  
         $encoded .= "document.write(&#39;$e&#39;);";  
    }  
    $encoded .= "document.write(&#39;$part3&#39;);";  
    foreach($linkText as $l)  
    {  
         $encoded .= "document.write(&#39;$l&#39;);";  
    }  
    $encoded .= "document.write(&#39;$part4&#39;);";  
    $encoded .= &#39;</script>';    
  
    return $encoded;  
} 


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.