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實體,以阻止垃圾郵件機器人。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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
檢視更多 >