note 76049 deleted from function.str_replace by bjori

From: Date: Sat, 30 May 2009 23:24:11 +0000
Subject: note 76049 deleted from function.str_replace by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156191@lists.php.net to get a copy of this message
Note Submitter: Ashus ---- This should basically protect the mail addresses on webpages: <?php function InsertMail($mail) { if ($mail=='') return ''; $mail = str_replace(array('@',':','.'), array('&#064;','&#058;','&#046;'), $mail); $mail = '<a href=mailto&#058;'.$mail.'>'.$mail.'</a>'; $len = strlen($mail); $i=0; while($i<$len) { $c = mt_rand(1,4); $par[] = (substr($mail, $i, $c)); $i += $c; } $join = implode('"+ "', $par); return '<script language=javascript> <!-- document.write("'.$join.'") //--> </script>'; } echo InsertMail ('user@example.com'); ?> Prints a javascript, that joins a bunch of randomly long substrings (1-4) of hyperlink prefix mailto and email address, considering that the chars . : and @ are replaced by html entities. It should work just fine.

« previous php.notes (#156191) next »