-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New additions to G-Lib, partially ported over from private repositories.
- Loading branch information
Showing
3 changed files
with
101 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | ||
|
||
/*************************************** | ||
* NOTES TO SELF: | ||
* tel_convert_vanity and tel_dialtring should be good, but untested. Add support for spaces as punctuation? | ||
* tel_format needs an overhaul. | ||
* phone_format needs to pass data to tel_format and trigger depreciated error. | ||
***************************************/ | ||
|
||
function phone_format() | ||
{ | ||
|
||
} | ||
|
||
function tel_format($str = '') | ||
{ | ||
// If we have not entered a phone number just return empty | ||
if (empty($str)) { | ||
return ''; | ||
} | ||
|
||
// Strip out any extra characters that we do not need only keep letters and numbers | ||
$str = preg_replace("/[^0-9A-Za-z]/", "", $str); | ||
|
||
// FORMAT | ||
if (strlen($str) == 10) { | ||
$num = preg_replace("/([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "$1.$2.$3", $str); | ||
} elseif (strlen($str) > 10) { | ||
$num = preg_replace("/([0-9a-zA-Z]{1})([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]+)/", "+$1 $2.$3.$4", $str); | ||
} else $num = $str; | ||
|
||
// RETURN | ||
return $num; | ||
|
||
} | ||
|
||
function tel_dialtring ($str) | ||
{ | ||
$str = tel_convert_vanity($str); | ||
|
||
if (preg_match('/^\+[\d]{1,3}[\(\)\d\.a-z]+$/i', $str)) | ||
{ | ||
return preg_replace('/[^\da-z\+]/i', '', $str); | ||
} | ||
elseif (preg_match('/^[\(]?[2-9]{1}[\d]{2}[\-\)\.]?[\da-z]{3}[\-\.]?[\da-z]{4}$/i', $str)) | ||
{ | ||
return '+1'.preg_replace('/[^\da-z\+]/i', '', $str); | ||
} | ||
else | ||
{ | ||
return $str; | ||
} | ||
} | ||
|
||
function tel_convert_vanity ($str) | ||
{ | ||
// SANITIZE, ALPHANUM ONLY | ||
$str = preg_replace("/[^0-9A-Za-z\*]/", "", $str); | ||
|
||
// CONVERT LETTERS TO NUMBERS | ||
$replace = array( '2'=>array('a','b','c'), | ||
'3'=>array('d','e','f'), | ||
'4'=>array('g','h','i'), | ||
'5'=>array('j','k','l'), | ||
'6'=>array('m','n','o'), | ||
'7'=>array('p','q','r','s'), | ||
'8'=>array('t','u','v'), | ||
'9'=>array('w','x','y','z')); | ||
// Replace each letter with a number | ||
// Notice this is case insensitive with the str_ireplace instead of str_replace | ||
foreach($replace as $digit=>$letters) { | ||
$str = str_ireplace($letters, $digit, $str); | ||
} | ||
|
||
return $str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters