One of the popular ways to hide your email on a web page from spam bots is to display the email as an image or to use the ‘[at]’ word instead of the ‘@’ sign. The code given here is yet another way to fight spam. The below function will let you to encode email or other links to their equivalent HTML entity encoded syntax. This will enable you to hide your web-page emails from spam bots. As the browser converts and displays the appropriate string from the encoding the user will be able to correctly see the email id, but a spam bot will have a difficult time to decode the encoded string. Of course we now have quite sophisticated crawlers that can work around this types of encoding, but for other crawlers that rely on regular expressions or other such simple methods, they will find it difficult to grab the email links from the page.
Encoding HTML characters
The function is quite simple. It encodes email, links or other string characters to their ‘Numeric character references’. For example ‘code‘ will be encoded to code – a decimal encoding or code – a hexadecimal encoding.
The function randomly encodes a character to a hex or decimal representation, so each page refresh will encode the same string to a different format.
This will convert the email ‘firstname.lastname@example.org’ to
designh ouse@ho st.com
As it uses a random base (decimal or hex), the actual results may differ from yours.