This article mainly introduces PHP to use regular expression format phone number method, interested in the friend's reference, I hope to be helpful to everyone.
The example in this article describes how PHP formats phone numbers. The specific analysis is as follows:
This function is only available for us phones, China phone needs to be modified by itself
function Format_phone ($phone) {$phone = Preg_replace ("/[^0-9]/", "", $phone); if (strlen ($phone) = = 7) return Preg_replace ("/([0-9]{3}) ([0-9]{4})/", "$1-$2", $phone); ElseIf (strlen ($phone) = = return Preg_replace ("/([0-9]{3}] ([0-9]{3}) ([0-9]{4})/", "($) $2-$3", $phone); else return $phone;}
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
A brief description of the magic methods available in PHP
Basic knowledge of PHP streaming
How to use foreach () in PHP