Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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