Znalazłem taki ciekawy skrypt kodujący e-mail:
  1. <?php
  2. echo encodeEmail('example@phpro.org');
  3.  
  4. /**
  5.  *
  6.  * Return ASCII value web use
  7.  *
  8.  * @param string
  9.  *
  10.  * @return string
  11.  *
  12.  */
  13. function makeASCII($char=0){
  14.  return '&#'.ord($char).';';
  15. }
  16.  
  17.  
  18. /**
  19.  *
  20.  * @Encode an email to ascii
  21.  *
  22.  * @parma string
  23.  *
  24.  * @return string
  25.  *
  26.  */
  27. function encodeEmail($email){
  28. /*** check if the filter has a var ***/
  29. if(filter_var($email, FILTER_VALIDATE_EMAIL) !== FALSE)
  30.    {
  31.    /*** split the email into single chars ***/
  32.    $charArray = str_split($email);
  33.    /*** apply a callback funcion to each array member ***/
  34.    $encodedArray = filter_var($charArray, FILTER_CALLBACK, array('options'=>"makeASCII"));
  35.    /*** put the string back together ***/
  36.    $encodedString = implode('',$encodedArray);
  37.    return '<a href="mailto:'.$encodedString.'">'.$encodedString.'</a>';
  38.    }
  39. else
  40.  {
  41.  return false;
  42.  }
  43. }
  44.  
  45. ?>


Zamienia on np. email:example@phpro.org na kod ASCII


Następnie kod jest poprawnie wyświetlany na stronie w postaci example@phpro.org (ale w kodzie strony ma on postać ASCII).

Jak sądzicie czy taki kod uchroni nas przed spamem na skrzynce e-mail?