将电子邮件地址字符转换为HTML实体以阻止垃圾邮件机器人。

原型

antispambot( string $email_address, int $hex_encoding )

参数

$email_address (string) (Required) 电子邮件地址。

$hex_encoding (int) (Optional)  设置为1以启用十六进制编码。

返回值

(string)  转换后的电子邮件地址

源文件

路径:wp-includes/formatting.php

<?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 ( $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 );
		}
	}
	return str_replace( '@', '&#64;', $email_no_spam_address );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/antispambot/