Skip to content

Instantly share code, notes, and snippets.

@milesleif
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save milesleif/7cecf92c749a3d754918 to your computer and use it in GitHub Desktop.

Select an option

Save milesleif/7cecf92c749a3d754918 to your computer and use it in GitHub Desktop.

Revisions

  1. milesleif revised this gist Apr 2, 2015. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions antispambot
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    // used by encode_emails
    // available in wp-core


    function antispambot( $email_address, $hex_encoding = 0 ) {
    $email_no_spam_address = '';
    for ( $i = 0; $i < strlen( $email_address ); $i++ ) {
    $j = rand( 0, 1 + $hex_encoding );
    if ( $j == 0 ) {
    $email_no_spam_address .= '&#' . ord( $email_address[$i] ) . ';';
    } elseif ( $j == 1 ) {
    $email_no_spam_address .= $email_address[$i];
    } elseif ( $j == 2 ) {
    $email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[$i] ) ), 2 );
    }
    }

    $email_no_spam_address = str_replace( '@', '&#64;', $email_no_spam_address );

    return $email_no_spam_address;
    }
  2. milesleif renamed this gist Apr 2, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. milesleif created this gist Apr 2, 2015.
    9 changes: 9 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function encode_emails($string){
    $pattern = "/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i";
    preg_match_all($pattern, $string, $split);
    foreach ($split[0] as $value) {
    $clean_value = antispambot($value);
    $string = str_replace($value, $clean_value ,$string);
    }
    return $string;
    }