PHPverse 2025

Voting

: min(seven, four)?
(Example: nine)

The Note You're Voting On

pedram at redhive dot com
24 years ago
In an attempt to dodge spam bots I've seen people (including myself) hex encode their email addresses in "mailto" tags. This is the small chunk of code I wrote to automate the process:

<?php
function hex_encode ($email_address) {
$encoded = bin2hex("$email_address");
$encoded = chunk_split($encoded, 2, '%');
$encoded = '%' . substr($encoded, 0, strlen($encoded) - 1);
return
$encoded;
}
?>

so for example:
<a href="mailto:&lt;?=hex_encode("[email protected]")?>">email me</a>

would produce the following address:
%70%65%64%72%61%6d%40%72%65%64%68%69%76%65%2e%63%6f%6d

-pedram

<< Back to user notes page

To Top