mirror of
				https://github.com/nerzhul/ocsms.git
				synced 2025-10-31 02:17:38 +00:00 
			
		
		
		
	modified: appinfo/formatphonenumber.php
Numbers will be formatted as in this examples: 00xx 1234567... => +xx1234567... (xxx)-yyy 1234567... => xxxyyy1234567... +xx (0) yyy 1234567... => +xxyyy1234567...
This commit is contained in:
		
							parent
							
								
									6816a92b89
								
							
						
					
					
						commit
						b19146be11
					
				| @ -10,9 +10,13 @@ | |||||||
|  */ |  */ | ||||||
| namespace OCA\OcSms\AppInfo; | namespace OCA\OcSms\AppInfo; | ||||||
| 
 | 
 | ||||||
|  | error_log("You messed up!", 3, "/var/tmp/my-errors.log"); | ||||||
|  | 
 | ||||||
| class FormatPhoneNumber { | class FormatPhoneNumber { | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| 	public static function formatPhoneNumber($pn) { | 	public static function formatPhoneNumber($pn) { | ||||||
|  | 
 | ||||||
| 		$ipnrxp = array(					// match international numbers with 1,2,3 digits
 | 		$ipnrxp = array(					// match international numbers with 1,2,3 digits
 | ||||||
| 			'#^(00|\+)(1\d\d\d)#',				// NANP
 | 			'#^(00|\+)(1\d\d\d)#',				// NANP
 | ||||||
| 			'#^(00|\+)(2[1|2|3|4|5|6|8|9]\d)#',		// +2(1|2|3|4|5|6|8|9)x
 | 			'#^(00|\+)(2[1|2|3|4|5|6|8|9]\d)#',		// +2(1|2|3|4|5|6|8|9)x
 | ||||||
| @ -33,20 +37,26 @@ class FormatPhoneNumber { | |||||||
| 		); | 		); | ||||||
| 
 | 
 | ||||||
| 		$ignrxp = array(					// match non digits and +
 | 		$ignrxp = array(					// match non digits and +
 | ||||||
| 			'#\(\d*\)|[^\d\+]#', | 			'#[^\d\+\(\)\[\]\{\}]#',			// everything but digit, +, (), [] or {}
 | ||||||
|  | 			'#(.+)([\(\[\{]\d*[\)\]\}])#',			// braces inside the number: +49 (0) 123 456789
 | ||||||
|  | 			'#[^\d\+]#'					// everything but digits and +
 | ||||||
|  | 		); | ||||||
|  | 		$ignrpl = array(					// replacements
 | ||||||
|  | 			'', | ||||||
|  | 			'$1', | ||||||
|  | 			'' | ||||||
| 		); | 		); | ||||||
| 		 | 		 | ||||||
| 		/* | 		/* | ||||||
| 			ToDo : make local settings in web-page | 			ToDo : make local settings in web-page | ||||||
| 		*/ | 		*/ | ||||||
| 		$lpnrxp = array(						// match local numbers
 | 		$lpnrxp = array(						// match local numbers
 | ||||||
| 			'#(^0)([^0])#',						// in germany : 0-xx[x[x]]-123456
 | 			'#(^0)([^0])#'						// in germany : 0-xx[x[x]]-123456
 | ||||||
| 		);								//
 | 		);								//
 | ||||||
| 		$lpnrpl = '+49$2';						// replace with +49 -xx[x[x]]-123456
 | 		$lpnrpl = '+49$2';						// replace with +49 -xx[x[x]]-123456
 | ||||||
| 
 |  | ||||||
| 		$tpn = trim($pn); | 		$tpn = trim($pn); | ||||||
| 		if( preg_match('#^[\d\+].*#',$tpn)) {				// start with digit or +
 | 		if( preg_match('#^[\d\+\(\[\{].*#',$tpn)) {			// start with digit, +, (, [ or {
 | ||||||
| 			$fpn = preg_replace($ignrxp, '', $tpn);			// replace everything but digits/+ with ''
 | 			$fpn = preg_replace($ignrxp, $ignrpl, $tpn);		// replace everything but digits/+ with ''
 | ||||||
| 			$xpn = preg_replace($lpnrxp, $lpnrpl, $fpn);		// replace local prenumbers
 | 			$xpn = preg_replace($lpnrxp, $lpnrpl, $fpn);		// replace local prenumbers
 | ||||||
| 			$ypn = preg_replace($ipnrxp, '+$2', $xpn);		// format to international coding +x[x[x]].....
 | 			$ypn = preg_replace($ipnrxp, '+$2', $xpn);		// format to international coding +x[x[x]].....
 | ||||||
| 		} else { | 		} else { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user