基本上我想要做的是使用javascript显示电子邮件,将这些部分组合在一起,形成电子邮件收集者无法看到的完整电子邮件地址。
我想带一个电子邮件地址,例如info@thiscompany.com并将其分解为: $ variable1 =“info”; $ variable2 =“thiscompany.com”;
这一切都是在PHP中完成的。
此致 JB
答案 0 :(得分:6)
list($variable1, $variable2) = explode('@','info@thiscompany.com');
答案 1 :(得分:2)
$parts = explode("@", $email_address);
假设$email_address = 'info@thiscompany.com'
然后$parts[0] == 'info'
和$parts[1] == 'thiscompany.com'
答案 2 :(得分:2)
您可以使用explode:
$email = 'info@thiscompany.com';
$arr = explode('@',$email);
$part1 = $arr[0]; // info
$part2 = $arr[1]; // thiscompany.com
答案 3 :(得分:2)
$email = "info@thiscompany.com";
$parts = explode("@", $email);
答案 4 :(得分:1)
在你自己推出之前试试这个(它做得更多):
function hide_email($email)
{ $character_set = '+-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
$key = str_shuffle($character_set); $cipher_text = ''; $id = 'e'.rand(1,999999999);
for ($i=0;$i<strlen($email);$i+=1) $cipher_text.= $key[strpos($character_set,$email[$i])];
$script = 'var a="'.$key.'";var b=a.split("").sort().join("");var c="'.$cipher_text.'";var d="";';
$script.= 'for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));';
$script.= 'document.getElementById("'.$id.'").innerHTML="<a href=\\"mailto:"+d+"\\">"+d+"</a>"';
$script = "eval(\"".str_replace(array("\\",'"'),array("\\\\",'\"'), $script)."\")";
$script = '<script type="text/javascript">/*<![CDATA[*/'.$script.'/*]]>*/</script>';
return '<span id="'.$id.'">[javascript protected email address]</span>'.$script;
}
答案 5 :(得分:0)
根据给定格式解析字符串的函数如何:sscanf。例如:
sscanf('info@thiscompany.com', '%[^@]@%s', $variable1, $variable2);