simplu27
7/12/2017 - 12:28 PM

Encode email string php

Encode email string php

<?php
// Source: http://www.codediesel.com/security/encode-your-email-links-to-prevent-spam/
 
function encodeString($email)
{
    $enc_email = '';
    srand();
 
    # Convert each character to decimal or hex representation
    for ($i=0; $i < strlen($email); $i++) {
 
        if(rand(0,1) == 0) {
            $enc_email .= "&#" . (ord($email[$i])) . ";";
        } else {
            $enc_email .= "&#X" . dechex(ord($email[$i])) . ";";
        }
    }
 
    return $enc_email;
}
 
// echo encodeString("designhouse@host.com");
 
?>