2010-10-29 75 views
3

我正在使用cakephp。我有textarea字段用戶粘貼數據,我使用tinymce插件來格式化文本。我已經警告用戶不要在textarea內輸入電話號碼或電子郵件地址。但是,我不想冒險。如何從textarea字段中提取電子郵件ID

有沒有一種方法,我可以提取textarea的電話號碼和電子郵件,並取代它像[email protected] ..

我感謝所有幫助。

謝謝。

回答

3

這裏的東西把我的頭頂部與隱藏更換電子郵件地址:

$str = "My e-mail is [email protected] Contact me for more details"; 
$str = preg_replace("/([a-zA-Z0-9\._]+)(@[a-zA-Z0-9\-\.]+)/", "hidden\\2", $str); 
print($str); 

電子郵件正則表達式是不是最好的,但它的東西,對於你的榜樣工程。您可以在http://www.regexlib.com/獲得更有趣的正則表達式(電子郵件和電話號碼),並使用它們與簡單的preg_replace。

1

,你可以: $string = "[email protected]";

$parts = explode("@",$string);

\\$parts[0] contains the local part

\\$parts[1] contains the domain.

請記住,(即使它是不常見),由RFC 822定義的格式允許「@」符號出現在引號內。這意味着:「[email protected]"@blablabla.com技術上是正確。

相關問題