jaymc Posted June 9, 2009 Share Posted June 9, 2009 I have a script that uses regex to check a string for an email, if it finds it removes However, It obviously cant find emails that are typed like this Hello this is my email j o h n @ h o t m a i l . c o m please add it There are also other tricks but what is the best way to combat this? Quote Link to comment https://forums.phpfreaks.com/topic/161543-email-remove/ Share on other sites More sharing options...
jxrd Posted June 9, 2009 Share Posted June 9, 2009 (\s)? Includes white space. Quote Link to comment https://forums.phpfreaks.com/topic/161543-email-remove/#findComment-852489 Share on other sites More sharing options...
jaymc Posted June 9, 2009 Author Share Posted June 9, 2009 Hmm Can you give me an example to try? Quote Link to comment https://forums.phpfreaks.com/topic/161543-email-remove/#findComment-852499 Share on other sites More sharing options...
Maq Posted June 9, 2009 Share Posted June 9, 2009 Can you show us your current regex? Quote Link to comment https://forums.phpfreaks.com/topic/161543-email-remove/#findComment-852503 Share on other sites More sharing options...
jaymc Posted June 9, 2009 Author Share Posted June 9, 2009 function extract_email($string) { $pattern = '/([a-z0-9])(([-a-z0-9._])*([a-z0-9-_]))*\@([a-z0-9])' . '(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9\.])+)/i'; preg_match ($pattern, $string, $matches); return $matches['0']; } What I do is have it return the match and then use str_replace to replace the email address with "..." Quote Link to comment https://forums.phpfreaks.com/topic/161543-email-remove/#findComment-852505 Share on other sites More sharing options...
jxrd Posted June 9, 2009 Share Posted June 9, 2009 Could try something like $pattern = '/([a-z0-9](\s)?)(([-a-z0-9._](\s)?)*([a-z0-9-_](\s)?))*\@([a-z0-9](\s)?)' . '(([a-z0-9-](\s)?)*([a-z0-9](\s)?))+' . '(\.([a-z0-9])([-a-z0-9_-](\s)?)?([a-z0-9\.](\s)?)+)/i'; Something like that anyway. Basically, just cram loads of (\s)? in there... Quote Link to comment https://forums.phpfreaks.com/topic/161543-email-remove/#findComment-852519 Share on other sites More sharing options...
jaymc Posted June 9, 2009 Author Share Posted June 9, 2009 That didnt work on this criteria $string = "hello john@hotmail. com you ok"; echo extract_email($string)"; Quote Link to comment https://forums.phpfreaks.com/topic/161543-email-remove/#findComment-852523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.