Skip to content

Instantly share code, notes, and snippets.

@mishajib
Last active August 29, 2022 18:00
Show Gist options
  • Save mishajib/43ad06262f1c755e3134aec24db0a151 to your computer and use it in GitHub Desktop.
Save mishajib/43ad06262f1c755e3134aec24db0a151 to your computer and use it in GitHub Desktop.
This helper helps to remove email & phone number from string/text.
<?php
function removeEmailAndPhoneFromString($string) {
// remove email
$string = preg_replace('/([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/', '*****', $string);
// remove phone
$string = preg_replace('/([0-9]+[\- ]?[0-9]+){4,}/', '*****', $string);
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment