函数原型
antispambot( string $email_address, int $hex_encoding ): string
函数描述
Converts email addresses characters to HTML entities to block spam bots.
是否弃用
未弃用
函数参数
-
$email_address
string
Required - Email address.
-
$hex_encoding
int
Optional - Set to 1 to enable hex encoding.
函数返回值
string Converted email address.
函数位置
File: wp-includes/formatting.php.
函数源码
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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 0.71 | Introduced. |

