#native_company# #native_desc#
#native_cta#

phonetest

By Matt Larson
on December 6, 2003

Version: 0.1

Type: Function

Category: Algorithms

License: GNU General Public License

Description: takes user input, parses out any non-numeric characters, and returns the phone number in the form (###) ###-#### x#### (if more than 10 digits).

<?php
	function phonetest($phone) {
	
	// tests for 10 or more digits and fomats in the form (###) ####-#### x#####
	// returns no value if phone number is not valid
	
		$len=strlen($phone);
		$phonenums="";
		for ($x=0;$x<$len;$x++){
			$c=substr($phone,$x,1);
			if (ereg("([0-9])",$c)){
				$phonenums=$phonenums.$c;
				}
			}
				
		if(strlen($phonenums)<10){
			return("");
			}
				
		$area=substr($phonenums,0,3);
		$exchange=substr($phonenums,3,3);
		$no=substr($phonenums,6,4);
			
		$newphone="(".$area.") ".$exchange."-".$no;
			
		if(strlen($phonenums)>10){
			$rest=strlen($phonenums)-10;
			$extention=substr($phonenums,10,$rest);
			$newphone=$newphone." x".$extention;
			}
			
			return($newphone);
		}
?>