-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.php
More file actions
45 lines (40 loc) · 997 Bytes
/
format.php
File metadata and controls
45 lines (40 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
class Format {
public static function flatten_digits($phone)
{
return preg_replace('`\D`','',$phone);
}
public static function phone($phone, $country_code, $display = true)
{
$phone = self::flatten_digits($phone);
if($display) {
if(strlen($phone)%2==0) {
$phone = preg_replace('`(\d{2})`','\1 ',$phone);
} else {
$phone = preg_replace('`^(\d{2})(\d{1})(\d{2})(\d{2})(\d{2})(\d{2})`','\1 \2 \3 \4 \5 \6',$phone);
}
}
if(strpos($phone,'0')===0) {
$phone = substr($phone, 1);
switch($country_code) {
case 'es':
$prefix='34';
break;
case 'be':
$prefix='32';
break;
default:
$prefix='33';
break;
}
$phone = '+'.$prefix.($display ? ' ':'').$phone;
} else {
$phone = '+'.$phone;
}
return $phone;
}
public function is_cell_phone($phone)
{
if(preg_match('`^0(6|7)`', $phone)) return true;
}
}