ascii.php
59 lines
| 1 | <?php |
| 2 | if ( ! function_exists( 'lim_email_ascii' ) ): |
| 3 | |
| 4 | // Info (optional) |
| 5 | $lim_email_ascii = array( |
| 6 | 'name' => 'JavaScript ASCII', |
| 7 | 'description' => 'Uses javascript (<a href="http://rumkin.com/tools/mailto_encoder/" target="_blank">original source</a>).', |
| 8 | ); |
| 9 | |
| 10 | /** |
| 11 | * lim_email_ascii() |
| 12 | * Based on function from Tyler Akins (http://rumkin.com/tools/mailto_encoder/) |
| 13 | * |
| 14 | * @package Lim_Email_Encoder |
| 15 | * @param string $email the email to encode |
| 16 | * @param string $display the display showing on the page |
| 17 | * @return string |
| 18 | */ |
| 19 | function lim_email_ascii( $email, $display ) { |
| 20 | $MailLink = '<a href="mailto:' . $email . '">' . $display . '</a>'; |
| 21 | |
| 22 | $MailLetters = ''; |
| 23 | |
| 24 | for ($i = 0; $i < strlen($MailLink); $i ++) |
| 25 | { |
| 26 | $l = substr($MailLink, $i, 1); |
| 27 | if (strpos($MailLetters, $l) === false) |
| 28 | { |
| 29 | $p = rand(0, strlen($MailLetters)); |
| 30 | $MailLetters = substr($MailLetters, 0, $p) . |
| 31 | $l . substr($MailLetters, $p, strlen($MailLetters)); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | $MailLettersEnc = str_replace("\\", "\\\\", $MailLetters); |
| 36 | $MailLettersEnc = str_replace("\"", "\\\"", $MailLettersEnc); |
| 37 | |
| 38 | $MailIndexes = ''; |
| 39 | for ($i = 0; $i < strlen($MailLink); $i ++) |
| 40 | { |
| 41 | $index = strpos($MailLetters, substr($MailLink, $i, 1)); |
| 42 | $index += 48; |
| 43 | $MailIndexes .= chr($index); |
| 44 | } |
| 45 | $MailIndexes = str_replace("\\", "\\\\", $MailIndexes); |
| 46 | $MailIndexes = str_replace("\"", "\\\"", $MailIndexes); |
| 47 | |
| 48 | return '<script language="javascript"><!-- |
| 49 | ML="'. $MailLettersEnc .'"; |
| 50 | MI="'. $MailIndexes .'"; |
| 51 | OT=""; |
| 52 | for(j=0;j<MI.length;j++){ |
| 53 | OT+=ML.charAt(MI.charCodeAt(j)-48); |
| 54 | }document.write(OT); |
| 55 | // --></script>'; |
| 56 | } |
| 57 | |
| 58 | endif; |
| 59 | ?> |