Created
April 17, 2015 08:19
-
-
Save Bogdaan/f6292f69d5d3a0a47821 to your computer and use it in GitHub Desktop.
Code formatter
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
<?php | |
class PCode | |
{ | |
private static $vector = array ( | |
0 => | |
array ( | |
'detect' => '247\\d\\d\\d\\d', | |
'mask' => '+247-####', | |
), | |
// <<<<< more codes here | |
); | |
/** | |
* | |
* @param unknown $phs | |
* @return string | |
*/ | |
public static function format($phn) | |
{ | |
$result = $phn; | |
foreach(self::$vector as $row) | |
{ | |
if(preg_match('/'.$row['detect'].'/s', $phn)) | |
{ | |
$reverse = array_reverse( str_split($phn) ); | |
$reverseMask = array_reverse( str_split($row['mask']) ); | |
$newresult = array(); | |
$ridx = 0; | |
foreach($reverseMask as $k) | |
{ | |
if($k=='#') | |
{ | |
$newresult[] = $reverse[$ridx]; | |
$ridx++; | |
} | |
else | |
$newresult[] = $k; | |
} | |
$result = implode('', array_reverse( $newresult )); | |
} | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment