Last active
August 29, 2015 14:18
-
-
Save milesleif/7cecf92c749a3d754918 to your computer and use it in GitHub Desktop.
Encode eMails-adddresses to unicode
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
| // used by encode_emails | |
| // available in wp-core | |
| function antispambot( $email_address, $hex_encoding = 0 ) { | |
| $email_no_spam_address = ''; | |
| for ( $i = 0; $i < strlen( $email_address ); $i++ ) { | |
| $j = rand( 0, 1 + $hex_encoding ); | |
| if ( $j == 0 ) { | |
| $email_no_spam_address .= '&#' . ord( $email_address[$i] ) . ';'; | |
| } elseif ( $j == 1 ) { | |
| $email_no_spam_address .= $email_address[$i]; | |
| } elseif ( $j == 2 ) { | |
| $email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[$i] ) ), 2 ); | |
| } | |
| } | |
| $email_no_spam_address = str_replace( '@', '@', $email_no_spam_address ); | |
| return $email_no_spam_address; | |
| } |
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
| function encode_emails($string){ | |
| $pattern = "/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i"; | |
| preg_match_all($pattern, $string, $split); | |
| foreach ($split[0] as $value) { | |
| $clean_value = antispambot($value); | |
| $string = str_replace($value, $clean_value ,$string); | |
| } | |
| return $string; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment