2011-01-16 2 views
1

[email protected]으로 # $ % # $ @ [email protected]#$#$2344324.com의 이메일을 삭제하고 싶습니다.
시도했으나 실패했습니다.
echo filter_var ("a # $ % # $ @ [email protected]#$#$2344324.com", FILTER_SANITIZE_EMAIL); // 결과 : # $ % # $ @ [email protected]#$#$2344324.compreg-replace를 사용하여 이메일에서 원하지 않는 문자를 제거하십시오.

이메일에서 특수 문자를 자르려면 (특수 문자를 삭제하려면 살균해야합니다). 아래 코드를 사용했지만 성공하지 못했습니다.

$string = preg_replace("/^[a-zA-Z0-9._%+-][email protected](?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}$/", "", "a#$%#[email protected]@#$#$2344324.com"); 

echo $string;//result: [email protected] -- unwanted characters trimmed here. 
+0

시도하고 당신이 그것을 시도하는 방법 당신이 뭘 하려는지 설명, 당신이 볼 것으로 예상 무엇을, 왜 당신이 본 것은 그 기대를 충족시키지 못했습니다. 이 사이트에는 실제 전문가가 있지만 일반적으로 전문 기술은 투시가 아닌 소프트웨어에 있지만 – davin

+1

그런 행동에는 의미가 없습니다. –

+2

'# $ % # $ @ [email protected]#$#$2344324.com을 돌리는 요점은 무엇입니까? 'a @ b.com'으로 – Gumbo

답변

0

여기 RFC 기반 솔루션 이미 있습니다 : http://fightingforalostcause.net/misc/2006/compare-email-regex.php

function is_valid_email_address($email){ 

     $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; 

     $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; 

     $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'. 
      '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; 

     $quoted_pair = '\\x5c[\\x00-\\x7f]'; 

     $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d"; 

     $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22"; 

     $domain_ref = $atom; 

     $sub_domain = "($domain_ref|$domain_literal)"; 

     $word = "($atom|$quoted_string)"; 

     $domain = "$sub_domain(\\x2e$sub_domain)*"; 

     $local_part = "$word(\\x2e$word)*"; 

     $addr_spec = "$local_part\\x40$domain"; 

     return preg_match("!^$addr_spec$!", $email) ? true : false; 
    } 
관련 문제