'PHP 전화번호 표시'에 해당되는 글 1건

728x90

킴스큐 RB 1.2 파일에 매번 동일한 함수를 추가하는 것은 불합리한 거 같아서

core 폴더에 함수를 추가했다.


function add_hyphen_telNo($tel)
{
    $tel = preg_replace("/[^0-9]/", "", $tel);    // 숫자 이외 제거
    if (substr($tel,0,2)=='02')
        return preg_replace("/([0-9]{2})([0-9]{3,4})([0-9]{4})$/", "\\1-\\2-\\3", $tel);
    else if (substr($tel,0,3)=='050')  // 평생번호
        return preg_replace("/([0-9]{4})([0-9]{3})([0-9]{4})$/", "\\1-\\2-\\3", $tel);
    else if (strlen($tel)=='8' && (substr($tel,0,2)=='15' || substr($tel,0,2)=='16' || substr($tel,0,2)=='18'))
        // 지능망 번호이면
        return preg_replace("/([0-9]{4})([0-9]{4})$/", "\\1-\\2", $tel);
    else
        return preg_replace("/([0-9]{3})([0-9]{3,4})([0-9]{4})$/", "\\1-\\2-\\3", $tel);
}


전화번호 표시를 자동으로 깔끔하게 표시하고 싶어서다.


파일에서는

<?php include_once $g['path_core'].'/function/string.func.php';?>

한줄만 추가해주고 나서 해당 전화번호를 표시할 부분에

<tr height=25>
    <td class="td1">휴대폰</td>
    <td class="td2"><?php echo add_hyphen_telNo($R['cellphone'])?></td>
</tr>


로 해주면 보기좋게 하이픈이 들어가서 표시된다.




블로그 이미지

Link2Me

,