Last active
April 17, 2024 08:34
-
-
Save joshuadavidnelson/8490f4984a93a218dad1 to your computer and use it in GitHub Desktop.
Obfuscate an email address output with PHP and CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>@' . $parts[1] . '</div>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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