antispambot() WP 0.71
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('mymail@example.com'); // In the code: mymail@gmail.com // On the screen: mymail@example.com
Changelog
Since 0.71 | Introduced. |
Code of antispambot() antispambot WP 5.6
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 );
}Related Functions
From category: Formatting
- absint()
- add_magic_quotes()
- backslashit()
- balanceTags()
- capital_P_dangit()
- convert_smilies()
- ent2ncr()
- force_balance_tags()
- links_add_target()