我正在寻找一种在网站源代码中混淆 mailtos 的方法。我想从这个开始:
href="mailto:president@whitehouse.gov"
对此:
href="" onmouseover="this.href='mai'+'lto:'+'pre'+'sid'+'ent'+'@wh'+'ite'+'hou'+'se.'+'gov'"</code>
我可能会改用 PHP 解决方案,就像这样(这样我只需要全局替换整个 mailto,我的源代码看起来会更好),但我花了太多时间查看 sed 和 Perl现在我不能停止思考如何做到这一点!有任何想法吗?
更新:在很大程度上基于 eclark 的解决方案,我最终想出了这个:
#!/usr/bin/env perl -pi
if (/href="mailto/i) {
my $start = (length $`) +6;
my $len = index($_,'"',$start)-$start;
substr($_,$start,$len,'" onmouseover="this.href=' .
join('+',map qq{'$_'}, substr($_,$start,$len) =~ /(.{1,3})/g));
}