그누보드에 있는 hyphen_hp_number 함수는 0505같은 번호에는 자릿수가 이상하게 나오더라구요.
|
답변 2개
채택된 답변
+20 포인트
4년 전
Copy
function add_hyphen($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 (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);
}
4년 전
정규식을 배워 보세요. 몇시간만 투자하면 훨씬 더 편해 집니다.
답변을 작성하려면 로그인이 필요합니다.