What potential pitfalls should be considered when formatting phone numbers in PHP, especially when dealing with international numbers?

When formatting phone numbers in PHP, especially international numbers, it is important to consider potential pitfalls such as varying formats, country codes, and special characters. To handle this, you can use a library like libphonenumber to parse and format phone numbers according to the international standards.

<?php
require_once('libphonenumber/vendor/autoload.php');

$phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$number = $phoneNumberUtil->parse('Phone number to format', null);
$formattedNumber = $phoneNumberUtil->format($number, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);

echo $formattedNumber;
?>