What is the recommended approach to remove phone numbers from a string in PHP using preg_replace?

When removing phone numbers from a string in PHP using preg_replace, the recommended approach is to use a regular expression pattern that matches phone numbers. This pattern should cover various phone number formats and account for different separators such as spaces, dashes, parentheses, and periods. By using preg_replace with this pattern, you can easily replace all instances of phone numbers in the string with an empty string.

$string = "My phone number is (123) 456-7890. Call me at 555-123-4567.";
$pattern = '/\(?(\d{3})\)?[\s-]?\d{3}[\s-]?\d{4}/';
$cleaned_string = preg_replace($pattern, '', $string);

echo $cleaned_string;