0

I need to remove all email and phone number from string in PHP. Can someone help me on this?

Kara
  • 6,115
  • 16
  • 50
  • 57
mahendura
  • 21
  • 1
  • 2

1 Answers1

3

This is just for a start up not a complete answer. You need to read more about regular expressions and its usage.

remove email addresses :

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

Reference

For phone numbers :

$text = preg_replace('/\+?[0-9][0-9()-\s+]{4,20}[0-9]/', '[removed]', $text);

this looks for:

a plus symbol (optional), followed by a number, followed by between 4-20 numbers, brackets, dashes or spaces, followed by a number

and replaces with the string [removed].

Reference

Community
  • 1
  • 1
Zigma
  • 529
  • 6
  • 37