<?php
    $intValid 
0;
    
$arrValid = array();
    
$arrValid[] = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org';
    
$arrValid[] = '01234567890@numbers-in-local.net';
    
$arrValid[] = '&\'*+-./=?^_{}~@other-valid-characters-in-local.net';
    
$arrValid[] = 'mixed-1234-in-{+^}-local@sld.net';
    
$arrValid[] = 'a@single-character-in-local.org';
    
$arrValid[] = '"quoted"@sld.com';
    
$arrValid[] = '"\e\s\c\a\p\e\d"@sld.com';
    
$arrValid[] = '"quoted-at-sign@sld.org"@sld.com';
    
$arrValid[] = '"escaped\"quote"@sld.com';
    
$arrValid[] = '"back\slash"@sld.com';
    
$arrValid[] = 'single-character-in-sld@x.org';
    
$arrValid[] = 'local@dash-in-sld.com';
    
$arrValid[] = 'letters-in-sld@123.com';
    
$arrValid[] = 'uncommon-tld@sld.museum';
    
$arrValid[] = 'uncommon-tld@sld.travel';
    
$arrValid[] = 'uncommon-tld@sld.mobi';
    
$arrValid[] = 'country-code-tld@sld.uk';
    
$arrValid[] = 'country-code-tld@sld.rw';
    
$arrValid[] = 'local@sld.newTLD';
    
$arrValid[] = 'numbers-in-tld@sld.xn--3e0b707e';
    
$arrValid[] = 'local@sub.domains.com';
    
$arrValid[] = 'bracketed-IP-instead-of-domain@[127.0.0.1]';
    
    
$intInvalid 0;
    
$arrInvalid = array();
    
$arrInvalid[] = '@missing-local.org';
    
$arrInvalid[] = '! #$%(),:;<>@[]\`|@invalid-characters-in-local.org';
    
$arrInvalid[] = '.local-starts-with-dot@sld.com';
    
$arrInvalid[] = 'local-ends-with-dot.@sld.com';
    
$arrInvalid[] = 'two..consecutive-dots@sld.com';
    
$arrInvalid[] = 'partially."quoted"@sld.com';
    
$arrInvalid[] = 'the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net';
    
$arrInvalid[] = 'missing-sld@.com';
    
$arrInvalid[] = 'sld-starts-with-dashsh@-sld.com';
    
$arrInvalid[] = 'sld-ends-with-dash@sld-.com';
    
$arrInvalid[] = 'invalid-characters-in-sld@! "#$%(),/;<>_[]`|.org';
    
$arrInvalid[] = 'local@second-level-domains-are-invalid-if-they-are-longer-than-sixty-three-characters.org';
    
$arrInvalid[] = 'missing-dot-before-tld@com';
    
$arrInvalid[] = 'missing-tld@sld.';
    
$arrInvalid[] = '';
    
$arrInvalid[] = 'missing-at-sign.net';
    
$arrInvalid[] = 'unbracketed-IP@127.0.0.1';
    
$arrInvalid[] = 'invalid-ip@127.0.0.1.26';
    
$arrInvalid[] = 'another-invalid-ip@127.0.0.256';
    
$arrInvalid[] = 'IP-and-port@127.0.0.1:25';
    
    
$str.= '<strong>TEST php fucntion filter_var FILTER_VALIDATE_EMAIL on PHP ' phpversion() . '</strong>';
    
$str.= '<p>';
    
$str.= 'Testing filter_var php function in completion of this test : <a target="_blank" href="http://fightingforalostcause.net/misc/2006/compare-email-regex.php">Comparing E-mail Address Validating Regular Expressions</a>';
    
$str.= '<br />';
    
$str.= 'This test run on PHP ' phpversion() . ', result should depend of your php version.';
    
$str.= '</p>';
    
$str.= '<div>';
        
$str.= '<div class="var_mail_valid">';
            
$str.= '<br />';
            
$str.= '<strong>These should be valid</strong>';
            
$str.= '<br />';
            
$str.= '<table>';
            foreach(
$arrValid as $strMail){
                
$str.= '<tr>';
                    
$str.= '<td>';
                    
$str.= $strMail;
                    
$str.= '</td>';
                    
$str.= '<td>';    
                    if(
filter_var($strMail,FILTER_VALIDATE_EMAIL)){
                        
$intValid++;
                        
$str.= '<div style="background-color:green;padding:0.2em;width:3em;text-align:center;">valid</div>';
                    } else {
                        
$str.= '<div style="background-color:red;;padding:0.2em;width:3em;text-align:center;">invalid</div>';
                    }
                    
$str.= '</td>';
                
$str.= '</tr>';
            }
            
$str.= '</table>';
        
$str.= '</div>';
        
$str.= '<div class="var_mail_invalid">';
            
$str.= '<br />';
            
$str.= '<strong>These should be invalid</strong>';
            
$str.= '<br />';
            
$str.= '<table>';
            foreach(
$arrInvalid as $strMail){
                
$str.= '<tr>';
                    
$str.= '<td>';
                    
$str.= $strMail;
                    
$str.= '</td>';
                    
$str.= '<td>';    
                    if(
filter_var($strMail,FILTER_VALIDATE_EMAIL)){
                        
$str.= '<div style="background-color:green;padding:0.2em;width:3em;text-align:center;">valid</div>';
                    } else {
                        
$intInvalid++;
                        
$str.= '<div style="background-color:red;;padding:0.2em;width:3em;text-align:center;">invalid</div>';
                    }
                    
$str.= '</td>';
                
$str.= '</tr>';
            }
            
$str.= '</table>';
        
$str.='</div>';
        
$str.= '<br />';
        
$str.= '<br />';
        
$str.='Valid: ' $intValid '/' count($arrValid) ;
        
$str.= '<br />';
        
$str.='Invalid: ' $intInvalid '/' count($arrInvalid);
    
$str.='</div>';
    
    echo 
$str;
?>