Jump to content

Email remove


jaymc

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/161543-email-remove/
Share on other sites

	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 "..."

Link to comment
https://forums.phpfreaks.com/topic/161543-email-remove/#findComment-852505
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/161543-email-remove/#findComment-852519
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.