Obscures email addresses in HTML to prevent spam bots from harvesting them.
Description
Typically this will randomly replace characters from the email address with HTML character references; however, when the hex encoding parameter is set, some characters will also be represented in their percent-encoded form. Because this function is randomized, the outputs for any given input may differ between calls. This helps diversify the ways the email addresses are obscured. When non-UTF-8 inputs are provided, any spans of invalid UTF-8 bytes will be passed through without any obfuscation. Example: $email = '[email protected]';
$obscured = antispambot( $email );
$obscured === 'noreply@example.com';
// Hex-encoding also obscures characters with percent-encoding.
$obscured = antispambot( $email, 1 );
$obscured === '%6eore%70l%79@%65x%61mple%2e%63%6fm';
// Non-UTF-8 characters are not obfuscated. "\xFC" is Latin1 "ü".
$obscured = antispambot( "b\[email protected]" );
$obscured === 'b�cher@library.de';
$obscured === "b\xFCcher@library.de"
Parameters
$email_addressstring
Email address.
$hex_encodingintoptional
Set to 1 to enable hex encoding.Default: 0
Return
string
Converted email address.
Uses · 3
_wp_scan_utf8()Finds spans of valid and invalid UTF-8 bytes in a given string.
Signature, return type and hooks compared across 5 parsed releases.
7.1.0
Masquerades multibyte characters.from the docblock
0.71
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/formatting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.