antispambot()
Converts email addresses characters to HTML entities to stop spam-bots from parsing your email.
No Hooks.
Return
String
. Converted email address.
Usage
antispambot( $email_address, $hex_encoding );
- $email_address(string) (required)
- Email address.
- $hex_encoding(int)
Set to 1 to enable hex encoding.
0
- encodes only with integers ({).
1
- encodes to hex (&x7B;).
Default: 0
Examples
#1 Encode email
echo antispambot('[email protected]'); // In the code: mymail@gmail.com // On the screen: [email protected]
Changelog
Since 0.71 | Introduced. |
antispambot() antispambot code WP 6.7.1
function antispambot( $email_address, $hex_encoding = 0 ) { $email_no_spam_address = ''; for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i++ ) { $j = rand( 0, 1 + $hex_encoding ); if ( 0 === $j ) { $email_no_spam_address .= '&#' . ord( $email_address[ $i ] ) . ';'; } elseif ( 1 === $j ) { $email_no_spam_address .= $email_address[ $i ]; } elseif ( 2 === $j ) { $email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[ $i ] ) ), 2 ); } } return str_replace( '@', '@', $email_no_spam_address ); }