View Single Post
Old 12-22-2004, 19:00   #3 (permalink)
Justin Koivisto
Civilians

 
Default Re: Hiding email address from spambots

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kerberos wrote:
| Neat article on how to hide e-mail addresses from spambots:
| http://www.phoenity.com/newtedge/hide_email_spambots/
| To date I have always used a Javascript, but it doesn't work with
| XHTML, however this CSS hack works fine with XHTML, and will protect
| e-mail addresses from being collected.
|

I've had good luck so far with this:

/**
* emailEncode
*
* Spits out email addresses using HTML entities instead of the actual
* characters as an attempt to prevent spam to these addresses.
* Searches for email addresses, links them, and encodes them.
*
* @param $x The content that contains the email address(es)
* @result Returns the input with addresses encoded
*/
function emailEncode($x){
~ $pattern='/([a-z][a-z0-9_.-\/\%]*@[^\s\"\)\?<>]+\.[a-z]{2,6})/i';
~ $search=array();
~ $replace=array();
~ if(preg_match_all($pattern,$x,$matches)){
~ if(isset($matches[0])){
~ // There should be at least one match from the string.
~ for($i=0;$i<count($matches[0]);$i++){
~ $search[]=$matches[0][$i];
~ $str='';
~ for($j=0;$j<strlen($matches[0][$i]);++$j){
~ $str.='&#'.ord($matches[0][$i]{$j}).';';
~ }
~ $replace[]='<a href="mailto:'.$str.'">'.$str.'</a>';
~ }
~ }
~ }
~ return str_replace($search,$replace,$x);
}

I just pass the entire content block into it... It translates
"spam@koivi.com" to
"spam@koivi.com"
~ (as a link)

- --
Justin Koivisto - spam@koivi.com
http://www.koivi.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFBye7cm2SxQ7JEbpoRAuWvAJ95DCYlvEPljXB2bhd4x6 gw7lhmugCfeO9S
4EvWnu+iaayt8c5EhEYWJF8=
=54NE
-----END PGP SIGNATURE-----
  Reply With Quote
 
Page generated in 0.68940 seconds with 14 queries