正文  软件开发 > PHP编程技术 >

电话号码格式化,

电话号码格式化, function format_phone($phone) { $phone = preg_replace("/[^0-9]/", "...

电话号码格式化,

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) == 10)
                return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/","$1-$2-$3",$phone);  //  400-152-8978   样式可以自己更改($1) $2-$3, 
                else
                    return $phone;
        }

http://www.bkjia.com/PHPjc/1223962.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1223962.htmlTechArticle电话号码格式化, function format_phone( $phone ) { $phone = preg_replace ("/[^0-9]/", "", $phone ); if ( strlen ( $phone ) == 7 ) return preg_replace ("/([0-9]{3})([0-9]{4}...