Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Last active April 17, 2024 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshuadavidnelson/8490f4984a93a218dad1 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/8490f4984a93a218dad1 to your computer and use it in GitHub Desktop.
Obfuscate an email address output with PHP and CSS
<?php
/**
* Obfuscate an email address php output with some CSS help
*
* @author Joshua David Nelson, josh@joshuadnelson.com
* Based on:
* @link http://perishablepress.com/best-method-for-email-obfuscation/
*/
// PHP Output - replace the $instance['email'] with whatever input/variable is storing your clean email address
if( $instance['email'] ) {
// Reverse the order of the email address - note that the CSS for this doesn't work in IE < 9.0
$email = strrev( $instance['email'] );
// separate out the host and the name
$parts = explode('@', $email );
// put it all back together, backwards (CSS will reverse it),
// with a hidden 'null' span and using an HTML character for the 'at' symbol
echo '<div class="email">' . $parts[0] . '<span>llun</span>&#64;' . $parts[1] . '</div>';
}
/**
* Obfuscate an email address php output with some CSS help
*
* @author Joshua David Nelson, josh@joshuadnelson.com
* Based on:
* @link http://perishablepress.com/best-method-for-email-obfuscation/
*/
/* CSS Output */
.email {
unicode-bidi: bidi-override; /* Doesn't work well in IE versions before 9.0 */
direction: rtl;
}
.email span {
display: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment