0

What PHP function or encoding method could allow you to convert an email address to a set of characters, then decoded again when needed? The email address would be publicly available to a certain program/audience, which handles conversions, but would not be harvested by spammers due to not being recognized as an email address.

Obviously it would have to have a perfect 1 to 1 conversion.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
Orangeman555
  • 1,179
  • 2
  • 21
  • 45

1 Answers1

4

You can do web safe encode and decode using this

// encode emailaddress
$email_encoded = rtrim(strtr(base64_encode($email), '+/', '-_'), '=');

 // decode email address
$email_decoded = base64_decode(strtr($email_encoded, '-_', '+/'));

It converts the + and / from the base64 alphabet in the more harmless - and _. The encoding step also removes the trailing = characters when needed.

chandresh_cool
  • 11,753
  • 3
  • 30
  • 45