A grasshopper in the middle of the road
Somewhere in the Croatian coast, a grasshopper was passing the road, very slowly.

Spam proof email presentation

Today web is full of encrypted email addresses thus making web non user friendly. This is due the growing number of spam bots harvesting web sites for email addresses.

The procedure to create more user friendly experience for the real users and at least fool most of the spam bots is the following:

  • Write content with valid email addresses
  • Use PHP to replace certain characters in the email address before presentation
  • Use jQuery to re-replace the original characters.
$(document).ready(function() {

    var real = $('div.real').html();

    real = real.replace(/\[\[\-\]\]/g, '@');

    real = real.replace(/\[\[\.\]\]/g, '.');

    $('div.real').html(real);

});

Above is the JavaScript code to be used with jQuery. Below the PHP function which can be called with the plain email address or some text including one email address.

function emailClean($mail) {

    // Find @ and get the text surrounding it, limited to white spaces.

    $pos1 = strpos($mail, '@');

    if ($pos1 === false) {

        return $mail;

    }

    // First white space before @

    $pos0 = strrpos(substr($mail, 0, $pos1), ' ');

    if ($pos0 === false) {

        $pos0 = 0;

    }

    // First white space after @

    $pos2 = strpos($mail, ' ', $pos1);

    if ($pos2 === false) {

        $pos2 = strlen($mail) - $pos0;

    }

    $actual = substr($mail, $pos0, $pos2 - $pos0);

    $replaced = str_replace('.', '[[.]]', $actual);

    $replaced = str_replace('@', '[[-]]', $replaced);

    $mail = substr_replace($mail, $replaced, $pos0, $pos2 - $pos0);

    return $mail;

}

You might want to use different combinations of the spoofing characters on order to create your unique algorithm.