2013-01-25 22 views
-1
$email_address_pattern="([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])[email protected]([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}"; 
$address= "[email protected]"; 
$length=strlen($address); 

for($position=0;$position<$length;) { 
    $match=preg_split($email_address_pattern,strtolower(substr($address,$position)),2); 
    print_r($match); 

    if(count($match)<2) 
     break; 

    $position+=strlen($match[0]); 
    $next_position=$length-strlen($match[1]); 
    $found=substr($address,$position,$next_position-$position); 

    if(!strcmp($found,"")) 
     break; 
    if(IsSet($addresses[$found])) 
     $addresses[$found]++; 
    else { 
     $addresses[$found]=1; 
     $position=$next_position; 
    } 
} 

我得到警告:使preg_split電子郵件模式

警告:使preg_split():未知的修飾詞 '+' 在/home/www/html/cusidevelopment/test.php在線10

我該如何解決它?

在此先感謝

+1

要麼你更新的問題,或使其可編輯,以便其他人可以。因爲我認爲,有些東西仍然缺失 –

回答

0

您必須添加開始和結束符號。添加ü給出了一個工作正則表達式。 (另外這個網站解釋你反引號的格式,所以你需要反斜槓轉義那些在你的問題。)

試試這個:

$email_address_pattern="ü([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])[email protected]([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\.)+[a-zA-Z]{2,6}ü"; 

當然,如你所知,正則表達式是不是一個很好的匹配描述郵件地址。

0

試試這個

$email_address_pattern="/([-!#\$%&'*+.\/0-9=?A-Z^_`a-z\{|\}~]+)@([-!#\$%&'*+\/0-9=?A-Z^_`a-z\{|\}~]+).[a-zA-Z]{2,6}/";