如何使用PHP在另一个字符串的中间添加字符串值?
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?
我有一个显示某些电子邮件的自动系统。 为了防止垃圾邮件机器人收到电子邮件,我想制作一个PHP脚本,在电子邮件中的'@'符号前面自动添加一个'[REMOVE THIS]'字符串。 p> \ n
substr_replace()和strpos()不起作用,因为substr_replace要求替换字符串与原始字符串的长度相同,而strpos()一次只能替换一个字母/符号。 我需要能够添加一个全新的字符串'[REMOVE THIS]',而不是删除原始字符串中的任何内容。 p>
我该怎么做? p> div>
As simple as this:
$obfuscated_email = str_replace('@', '[REMOVE THIS]@', $real_email);
and back again:
$real_email = str_replace('[REMOVE THIS]', '', $obfuscated_email);
In other words, name@site.com becomes name[REMOTE THIS]@site.com ?
<?php
$email = "name@site.com";
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.