Last active
May 8, 2018 17:39
-
-
Save mullens/9750940 to your computer and use it in GitHub Desktop.
Outputs a crawl-safe email with a working "mailto:" link using JavaScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function safe_email($email){ | |
| $bademail = str_replace("@"," [at] ",$email); | |
| $emailid = rand(0,1000000000000); | |
| $data = "<a href='#' id='email$emailid'>$bademail</a>"; | |
| $data .= '<script type="text/javascript">'; | |
| $jsemail = substr($email, 0, 4).'" + "'.substr($email, 4); | |
| $data .= 'jQuery("#email'.$emailid.'").html("'.$jsemail.'").attr("href","mailto:'.$jsemail.'")'; | |
| $data .= '</script>'; | |
| return $data; | |
| }; | |
| //USAGE | |
| echo safe_email("[email protected]"); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment