antispambot

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

Description

(string) antispambot( (string) $email_address, (int) $hex_encoding = 0 ); 

Returns (string)

Converted email address.

Parameters (2)

0. $email_address (string)
The email address.
1. $hex_encoding — Optional. (int)
Set to 1 to enable hex encoding.

Usage

  1. if ( !function_exists( 'antispambot' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // The email address. 
  5. $email_address = ''; 
  6.  
  7. // Optional. Set to 1 to enable hex encoding. 
  8. $hex_encoding = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = antispambot($email_address, $hex_encoding); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function antispambot( $email_address, $hex_encoding = 0 ) { 
  2. $email_no_spam_address = ''; 
  3. for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i++ ) { 
  4. $j = rand( 0, 1 + $hex_encoding ); 
  5. if ( $j == 0 ) { 
  6. $email_no_spam_address .= '&#' . ord( $email_address[$i] ) . ';'; 
  7. } elseif ( $j == 1 ) { 
  8. $email_no_spam_address .= $email_address[$i]; 
  9. } elseif ( $j == 2 ) { 
  10. $email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[$i] ) ), 2 ); 
  11.  
  12. return str_replace( '@', '@', $email_no_spam_address );