Home > Backend Development > PHP Tutorial > PHP编码电子邮件地址,防止被垃圾邮件程序收集

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

WBOY
Release: 2016-06-20 13:03:05
Original
1587 people have browsed it

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;  
} 
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template