使用这个脚本可以把邮件地址隐藏以来,不会轻易被网络上的robot发掘出来。
函数页面hide_mail_address.php
- <?php
- function hide_mailto($mail, $label, $subject = "", $body = "") {
- $chars = preg_split("//", $mail, -1, PREG_SPLIT_NO_EMPTY);
- $new_mail = "<a href=/"mailto:";
- foreach ($chars as $val) {
- $new_mail .= "&#".ord($val).";";
- }
- $new_mail .= ($subject != "" && $body != "") ? "?subject=".$subject."&body=".$body : "";
- $new_mail .= "/">".$label."</a>";
- return $new_mail;
- }
- ?>
调用页面hide.htm
- <?php
- $pattern = "[a-z0-9_-]+(/.[a-z0-9_-]+)*";
- $pattern .= "@([0-9a-z][0-9a-z-]*[0-9a-z]/.)+([a-z]{2,4})";
- if (preg_match("/".$pattern."/i")) {
- // code...
- ?>
- <form method="post" action="hide_mail_address.php" style="margin-top:20px;">
- <div>
- <label for="link">Link text: </label>
- <input name="link" type="text" id="link" value="" size="25" />
- </div>
- <div>
- <label for="mail">E-mail address: </label>
- <input name="mail" type="text" id="mail" value="" size="25" />
- </div>
- <div>
- <label for="subj">Subject: </label>
- <input name="subj" type="text" id="subj" value="" size="50" />
- </div>
- <div>
- <label for="msg">Some message: </label>
- <input name="msg" type="text" id="msg" value="" size="50" />
- </div>
- <div style="padding:0 0 10px 110px;">
- <input name="submit" type="submit" value="Submit" />
- </div>
- </form>
原文http://www.finalwebsites.com/demos/hide_mail_address.php
我的油箱zizzy@yeah.net,隐藏加密的结果,
<a href="mailto:zizzy@yeah.net?subject=Hi!&body=Hi!zizzy....I love you!">zizzy</a>
<script type="text/javascript">document.write('');</script>