도메인 추출 정규식 > 정보공유

본문 바로가기

정보공유

일반글
PHP

도메인 추출 정규식

페이지 정보

게시물QR코드

본문

if ( ! function_exists('getDomainName'))

{

    function getDomainName($url)

    {

        $value = strtolower(trim($url));

        $url_patten = '/^(?:(?:[a-z]+):\/\/)?((?:[a-z\d\-]{2,}\.)+[a-z]{2,})(?::\d{1,5})?(?:\/[^\?]*)?(?:\?.+)?$/i';

        $domain_patten = '/([a-z\d\-]+(?:\.(?:asia|info|name|mobi|com|net|org|biz|tel|xxx|kr|co|so|me|eu|cc|or|pe|ne|re|tv|jp|tw)){1,2})(?::\d{1,5})?(?:\/[^\?]*)?(?:\?.+)?$/i';

 

        if (preg_match($url_patten, $value))

        {

            preg_match($domain_patten, $value, $matches);

            $host = (!$matches[1]) ? $value : $matches[1];

        }

        return $host;

    }

}


echo getDomainName('gnuwiz.com/index.php');

댓글목록

등록된 댓글이 없습니다.

  • Addr.부산광역시 동구 중앙대로 319, 9층 L4호(초량동, 부산YMCA빌딩) Email. gnuwiz@naver.com
  • BR. 625-68-00172 TRC. 2019-부산해운대-1186 TEL. 0507-1382-2790
All rights reserved.