2010-11-08 45 views
1

有誰知道一個好的解決方案,可以從PHP使用,將有效地移除聯繫人信息,如電話號碼,電子郵件地址,甚至可能從文檔中的聯繫人地址?從文檔中自動刪除聯繫人信息

更新

嗨,這裏是我想出了這麼遠,它工作得很好。

function sanitizeContent($content) 
    {  
     // emails - even containing white space characters like this 't e s t @ ba d . co m' 
     $content = preg_replace('/([A-Za-x-0-9\s\_\.]{1,50})([email protected])@([A-Za-x-0-9\s\_\.]{1,50})/', '[email removed]', $content);  

     // urls 
     $content = preg_replace('/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i', '[link removed]', $content); 

     // phone numbers    
     $content = preg_replace('/(\d)?(\s|-|.|\/)?(\()?(\d){3}(\))?(\s|-|.|\/){1}(\d){3}(\s|-|.|\/){1}(\d){4}/', '[phone removed]', $content); 
     $content = preg_replace('/[0-9\.\-\s\,\/(x|ext)]{5,50}/', '[phone removed]', $content);  

     // addresses???? 

     return $content; 
    } 

有誰有地址的任何想法,我想,也許想出一個方法來檢測城市,州郵編隨後還之前剔除X字符。它可能會意外地破壞一些數據,但這可能比披露更好。如果有人遇到這種情況,我會非常感興趣。

+2

你問太多。你將不得不創建AI。 – metrobalderas 2010-11-08 20:22:48

+0

我能想到的最簡單的解決方案是開發一組符合相關數據的正則表達式,並用某種通知替換匹配項(如_「聯繫信息已刪除」_)。 – jwueller 2010-11-08 20:24:15

+0

您需要具體說明要刪除的數據。您將無法擊敗文檔中的隱藏通道。 – Incognito 2010-11-08 20:29:35

回答

1

使用正則表達式。

您可以使用preg_replace來做到這一點。

$pattern = "/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i"; 
$replacement = "[removed]"; 
preg_replace($pattern, $replacement, $string); 

的電子郵件:

$pattern = "/[^@\s]*@[^@\s]*\.[^@\s]*/"; 
$replacement = "[removed]"; 
preg_replace($pattern, $replacement, $string); 

對於網址: