• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Email addresses with a "+" are not parsed correctly

#11
[eluser]sophistry[/eluser]
ok, got a few more tweaks here that should be a "final" version.

fixed the "capture dot at end of pattern problem"
made it much more strict overall... (see test cases in controller below).

EDIT: replaced a-z0-9 with [:alnum:] character class
Code:
<?php

class Test extends Controller {

    function Test()
    {
        parent::Controller();
    }
        
    function index()
    {
        $chars = '-.a-zA-Z0-9#!$%&*+/\'=?^_`{}|~';
        $len = strlen($chars);
        $i=0;
        print_r($chars); echo '<br>';
        while ($i<$len)
        {
            preg_match(":[$chars]:", $chars[$i], $matches);
            $i++;
            print_r($matches[0]);
        }
        
        // test on "real" addresses
        $strs = array(
                    "back|to=school~w0w.does+this^[email protected]",
                    "back{to}school-does+this^[email protected]",
                    'back{to}school#[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    'h#[email protected]',
                    '[email protected]',
                    'h$[email protected]',
                    'h%[email protected]',
                    'h&r;@example.com',
                    'h*[email protected]',
                    '[email protected]',
                    'h/[email protected]',
                    "h'[email protected]",
                    '[email protected]',
                    '[email protected]',
                    'h^[email protected]',
                    '[email protected]',
                    'h`[email protected]',
                    'h{[email protected]',
                    'h}[email protected]',
                    'h|[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    );
        $chars_not_dot = '-a-z0-9#!$%&*+/\'=?^_`{}|~';
        foreach ($strs as $s)
        {
            preg_match_all(";([$chars_not_dot](?:[$chars_not_dot]|[.](?![.]))*)@((?:[[:alnum:]])(?:[-[:alnum:]]*)(?:[[:alnum:]])(?:[.](?![.]))(?:[[:alnum:]])(?:[-[:alnum:]]|[.](?![.]))+(?:[[:alnum:]]));i", $s, $matches);
            $this->_p($s);
            $this->_p($matches);
        }
    
    }
    
    function _p($d) {echo'<pre>';print_r($d);echo'</pre>';}

}

/* End of file test.php */

please test and examine.


Messages In This Thread
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 07:59 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:43 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:50 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:54 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 10:17 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 10:49 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 11:11 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 11:38 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 09:58 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 10:29 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 12:07 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 12:26 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-30-2008, 04:20 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-01-2008, 12:02 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-10-2008, 10:25 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-11-2008, 06:45 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-11-2008, 07:47 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.