<?php /** * * Return ASCII value web use * * @param string * * @return string * */ function makeASCII($char=0){ return '&#'.ord($char).';'; } /** * * @Encode an email to ascii * * @parma string * * @return string * */ function encodeEmail($email){ /*** check if the filter has a var ***/ if(filter_var($email, FILTER_VALIDATE_EMAIL) !== FALSE) { /*** split the email into single chars ***/ $charArray = str_split($email); /*** apply a callback funcion to each array member ***/ /*** put the string back together ***/ return '<a href="mailto:'.$encodedString.'">'.$encodedString.'</a>'; } else { return false; } } ?>
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?