php 도메인 추출 정규식 본문
php 도메인 추출 정규식
- 2016. 5. 7. 01:52
원본/출처:
http://setint.tistory.com/entry/php-%EB%8F%84%EB%A9%94%EC%9D%B8-%EC%B6%94%EC%B6%9C-%EC%A0%95%EA%B7%9C%EC%8B%9D
http://setint.tistory.com/entry/php-%EB%8F%84%EB%A9%94%EC%9D%B8-%EC%B6%94%EC%B6%9C-%EC%A0%95%EA%B7%9C%EC%8B%9D
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; } }
반응형
RECENT COMMENT