Are there best practices for handling user input in PHP to prevent the display of sensitive information like phone numbers?

When handling user input in PHP, it is important to sanitize and validate the data to prevent the display of sensitive information like phone numbers. One way to achieve this is by using regular expressions to detect and mask phone numbers before displaying them to the user.

// Sample code to mask phone numbers in user input
$userInput = "My phone number is 123-456-7890";
$maskedInput = preg_replace('/\b\d{3}[-.]?\d{3}[-.]?\d{4}\b/', 'XXX-XXX-XXXX', $userInput);

echo $maskedInput;