Created
July 27, 2017 10:47
-
-
Save anova/0d341b7cee5f330522781ed2d581038c to your computer and use it in GitHub Desktop.
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 | |
function phone_format( $phone ) | |
{ | |
$retVal = $phone; | |
//telefon ile ilgili islemler | |
if (0 === strlen($retVal)) {//telefon numarasi yoksa hic ugrasma | |
return $retVal; | |
} | |
//tireleri kaldır | |
$retVal = str_replace('-', '', $retVal); | |
//boşlukları kaldır | |
$retVal = str_replace(' ', '', $retVal); | |
//istanbul avrupa yakasi telefonlarinda alan kodu yazilmadigi oluyor. | |
//bu durumu kontrol edip duzenleyen kod | |
if (7 === strlen($retVal)) { | |
$retVal = '0212' . $retVal; | |
} | |
//başında 0 yok ise 0 ekle | |
if (strpos($retVal, '0') !== 0) { | |
$retVal = '0' . $retVal; | |
} | |
//11 karakterden fazla ise, ilk 11 karakteri al | |
if (strlen($retVal) > 11) { | |
$retVal = mb_substr($retVal, 0, 11); | |
} | |
//bosluklar ekle ( https://stackoverflow.com/a/4708314 ) | |
if (preg_match('/^(\d{4})(\d{3})(\d{2})(\d{2})$/', $retVal, $matches)): | |
array_shift($matches); | |
$retVal = implode(' ', $matches); | |
endif; | |
return $retVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment