Little script that might help against some email-/webcrawlers
| From: | Frank Arensmeier | Date: | Mon, 20 Nov 2006 12:54:45 +0000 |
| Subject: | Little script that might help against some email-/webcrawlers | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-244870@lists.php.net to get a copy of this message | ||
Hello
FYI
===============
Since I published email adresses to colleges of mine on our contact pages some months ago, the amount of spam mail has increased dramatically recently. So, I thought of how to make life for email-/web-crawlers a little bit harder. Of course, there are plenty "solutions" out there. But most of them use JavaScript to some extend. And since I am very concerned about availability/usability, I came up with this script:
<?php
// this function will return the input string encoded in ASCII values
// e.g. "test" will be outputted as "test"
function encode_email ( $str )
{
$out = "";
if ( empty ( $str ) ) {
return false;
}
$pieces = preg_split ( "//", $str );
foreach ( $pieces as $key => $piece ) {
if ( ord ( $piece ) ) {
$out .= "&#" . ord ( $piece ) . ";";
}
}
return $out;
}
?>
Call the function e.g. by:
<a href="mailto:<?php echo encode_email ("me@myself.com" ); ?>">Mail me!<a/>
/frank