2012-12-19 33 views
0

我需要從下面的html代碼的preg_match,輪不到電子郵件地址

<a href="mailto:[email protected]" rel="nofollow">Email Developer</a> 

檢索電子郵件數據我已經使用這個代碼以獲取電子郵件地址,但它沒能得到它。

preg_match('@^(?:mailto:)?([^/]+)@i', $data, $matches); 
$email = $matches[1]; 
echo $email; 

你能看出什麼問題?

+0

http://stackoverflow.com /問題/ 4258435 /預浸匹配到提取物的mailto上錨 –

回答

0

你剛纔所能做的就是

  • 剛剛剝離的mailto:從href屬性
  • 然後過濾郵件ADRESS

$string = '<a href="mailto:[email protected]" rel="nofollow">Email Developer</a>'; 
$parsing = new SimpleXmlElement($string); 
$attrs = (array)$parsing->attributes(); 
$mail = str_replace('mailto:','',$attrs['href']); 
if(filter_var($mail,FILTER_VALIATE_MAIL)){//if it is a good email 
    //goooo 
} 
相關問題