If you build a website in these days. You must be very alerted by the spambots that are crawling trough your site. When I build my blog, I was very aware of this and made some simpel yet effective code to protect some of my html by using Javascript.
I see lots of website just doing mymail [at] yourwebsite [dot] com. This will proberply help for some of the spambots. But definitely not all! If I was a spambot, I would also looking for the [at]'s and [dot]'s, and also the {at}'s and {dot}'s like I do.
Here is the snippet:
function protect( $s ) { $s = str_replace( "\n", ' ', str_replace( "\r", ' ', $s ) ); $a = array(); $p = 0; $l = strlen( $s ); while( $p < $l ) { $n = rand( 1, 4 ); $a[] = substr( $s, $p, $n ); $p += $n; } asort( $a ); $j = 'var a = new Array();'; foreach( $a as $k => &$v ) { $j .= "a[$k] = '" . addslashes( $v ) . "';"; } $j .= 'document.write( a.join("") );'; return '<script language="javascript">' . $j . '</script>'; }
You can just do the following to write the protected code.
echo protect( 'Help! Protect me from these evil spambots! Please!' ); echo protect( '<a href="mailto:insert.mail@address.here">e-mail me</a>' );
What it does is. It cuts the inputted string into random length en put them into a array. Sort the array to make ik not linear. And let Javascript join it into a string and document.write() it. This time Javascript writing it and your code would not be seen as plain text in the html source code.