WordPress at a glance

antispambot() WP 1.0

Converts email addresses characters to HTML entities to block spam bots.

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.
Default: 0

Code of antispambot: wp-includes/formatting.php VER 4.9.8

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

Related Functions

From category: Formatting

No comments
    Hello, !     Log In . Register