php 문자열에서 숫자만 추출하기 > PHP

본문 바로가기
사이트 내 전체검색

PHP

php 문자열에서 숫자만 추출하기

페이지 정보

profile_image
작성자 최고관리자
댓글 0건 조회 6,274회 작성일 21-02-09 11:48

본문

$text = "0#12.3f4hhds56.7dd890";

 $StelInt = ereg_replace("[^0-9]", "", $text);
  또는
$StelInt = preg_replace ("/[^0-9]*/s", "", $text);

 --> 하단은 일반적인 전화번호 보는 형식으로 만들기
if(substr($StelInt,0,1) == 0)
 {
        if(substr($StelInt,0,2) == 02)
        {
                $Stel =substr($StelInt,0,2) . "-" . substr($StelInt,2,-4)  . "-" . substr($StelInt,-4);
        }
        else
        {
                $Stel =substr($StelInt,0,3) . "-" . substr($StelInt,3,-4)  . "-" . substr($StelInt,-4);
        }       
 }
 else
 {
        $Stel =substr($StelInt,0,-4)  . "-" . substr($StelInt,-4);
 }

 echo "org $text <br>Stel $Stel";

 --> result <---
org 0#12.3f4hhds56.7dd890
 Stel 012-3456-7890

 =====================================================
밑에는 다른 방법

$hp1 = substr($StelInt,0,3);
 $hp2 = substr(substr($StelInt,0,-4),3);
 $hp3 = substr($StelInt,-4);

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

  • 게시물이 없습니다.

접속자집계

오늘
1,801
어제
4,039
최대
6,642
전체
830,316
contact : webmaster@beautipia.co.kr
Copyright © beautipia.co.kr. All rights reserved.