Last active
September 24, 2015 03:07
-
-
Save niksumeiko/657918 to your computer and use it in GitHub Desktop.
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 tep_rewrite_email($content) { | |
$email_patt = '([A-Za-z0-9._%-]+)\@([A-Za-z0-9._%-]+)\.([A-Za-z0-9._%-]+)'; | |
$mailto_pattern = '#\<a[^>]*?href=\"mailto:\s?' . $email_patt . '[^>]*?\>[^>]*?<\/a\>#'; | |
$rewrite_result = '<span class="mailme">\\1 AT \\2 DOT \\3</span>'; | |
$content = preg_replace($mailto_pattern, $rewrite_result, $content); | |
$content = preg_replace('#' . $email_patt . '#', $rewrite_result, $content); | |
return $content; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHP function that finds emails in the given output and converts them to {{holder}} AT {{domain}} DOT {{zone}} format. I have created this function to fight against spam bots. The idea was to convert output into this custom format on the Backend side printing this into HTML page and then find, parse printed HTML element with JavaScript to encode it back to human-readable email format.
Example:
echo tep_rewrite_email('[email protected]');
// Prints <span class="mailme">email AT example DOT com</span>