Skip to content

Instantly share code, notes, and snippets.

View mullens's full-sized avatar

Lucas Mullens mullens

  • Table Toad
  • Madison, WI
View GitHub Profile
@mullens
mullens / safe_email.php
Last active May 8, 2018 17:39
Outputs a crawl-safe email with a working "mailto:" link using JavaScript.
<?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;