antispambot

函数
antispambot ( $email_address, $hex_encoding = 0 )
参数
  • (string) $email_address Email address.
    Required:
  • (int) $hex_encoding Optional. Set to 1 to enable hex encoding.
    Required:
返回值
  • (string) Converted email address.
定义位置
相关方法
sanitize_postis_monthunstick_postgrant_super_adminis_robots
引入
0.71
弃用
-

antispambot: 这是一个WordPress的函数,用于混淆电子邮件地址,以保护它们免受垃圾邮件的侵害。它需要一个参数:要混淆的电子邮件地址。

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

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 );
}

常见问题

FAQs
查看更多 >