1

I have an automated system displaying certain e-mails. To prevent spam bots from picking up the e-mails I would like to make a php script that automatically adds a '[REMOVE THIS]' string right before the '@' sign in an e-mail.

substr_replace() and strpos() don't work because substr_replace requires that the replacing string be the same length as the original piece of string, and strpos() can only replace one letter/symbol at a time. I need to be able to add in a whole new piece of string, '[REMOVE THIS]', while not deleting anything from the original string.

How do I do this?

3 Answers 3

1

In other words, [email protected] becomes name[REMOTE THIS]@site.com ?

<?php
$email = "[email protected]";
echo str_replace("@", "[REMOVE THIS]@", $email);
?>

Or, you can use :

http://www.wbwip.com/wbw/emailencoder.html

Type in your e-mail, get the encoded version, put it in your site and it will display your proper e-mail and bots won't be able to grab it, as its just code although it echos out the real result.. but when bots searching through the code, all they will see is code.

Sign up to request clarification or add additional context in comments.

Comments

0

preg_replace() preg_replace("/\@/", "[REMOVE THIS]@", $emailaddress)

2 Comments

For a simple replace like this str_replace will suffice.
Although I used a simple example, you might want to add in the regex for making sure you are putting it in front of an email address and not apart of something else. Although, the regex for validing email is the worst i've ever seen. :)
0

As simple as this:

$obfuscated_email = str_replace('@', '[REMOVE THIS]@', $real_email);

and back again:

$real_email = str_replace('[REMOVE THIS]', '', $obfuscated_email);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.