<mySearch ⁄>
<mySnippets order="rand" ⁄>
<myContacts ⁄><email ⁄>
<windows live messenger ⁄>
<myCurriculum type="pdf" ⁄>
<myBlog show="last" ⁄>
<myNews show="rand" ⁄>
<myNews type="cat" ⁄>
<myQuote order="random" ⁄>Transportai um punhado de terra todos os dias e fareis uma montanha
<myPhoto order="random" ⁄>
<myAdSense ⁄>
<myVisitorsMap ⁄>
<?php /** * Class ProtectEmail * * This class implements a few possible methods * to protect e-mail addresses from spam bots * * @author pedrocorreia.net */ class ProtectEmail{ private $_email; /** * Constructor * * @param String E-mail */ public function __construct($email){ if($this->_IsValid($email)) $this->_email=$email; else throw new Exception("EMAIL_IS_NOT_VALID"); } /** * "Beautify" e-mail by converting symbols to strings * * @return String */ public function Beautifier(){ if(!$this->_email) throw new Exception("EMAIL_NOT_SPECIFIED"); $search_for=array("/\./","/@/","/-/"); $replace_with=array(" Dot "," At ", " Hyphen "); return $this->Encoder(preg_replace($search_for,$replace_with,$this->_email)); } /** * Encode all elements in a String to their ascii codes * * note: if no argument's specified, the string encoded * will be the attribute defined in the constructor * * @param String [Optional] * @return String */ public function Encoder($email=""){ if(!$email) $email=$this->_email; if(!$email) throw new Exception("EMAIL_NOT_SPECIFIED"); $count=strlen($email); $encoded_str=array(); for ($i = 0; $i < $count; $i++){ $char=ord($email{$i}); $encoded_str[$i] = "&#$char;"; } return implode("",$encoded_str); } /** * Check if is a valid e-mail address * * note: complete credits to http://www.ilovejackdaniels.com/php/email-address-validation/ * * @param String * @return String */ private function _IsValid($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } } ?>
<?php include_once("class.ProtectEmail.php"); $email="email@my-domain.com.pt"; try{ $protected_email=new ProtectEmail($email); } catch (Exception $ex){ echo $ex->getMessage(); return ; } //we have a valid object if($protected_email){ try{ $email_encoded=$protected_email->Encoder(); } catch (Exception $ex){ echo $ex->getMessage(); } try{ $email_beautified=$protected_email->Beautifier(); } catch (Exception $ex){ echo $ex->getMessage(); } $email_link="<a href='mailto:$email_encoded'>$email_beautified</a>"; echo "$email_encoded<br/><br/>$email_beautified<br/><br/>$email_link"; } ?>