URL¿¡¼ µµ¸ÞÀθ¸ ÃßÃâÇϱâ |
|
|
 |
10³â Àü |
/**
* µµ¸ÞÀÎ¸í¿¡¼ ¸ÞÀÎ »çÀÌÆ®¸í¸¸ °¡Á®¿À±â
*/
function getHostName($url)
{
$value = strtolower(trim($url));
if (preg_match('/^(?:(?:[a-z]+):\/\/)?((?:[a-z\d\-]{2,}\.)+[a-z]{2,})(?::\d{1,5})?(?:\/[^\?]*)?(?:\?.+)?$/i', $value))
{
preg_match('/([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', $value, $matches);
$host = (!$matches[1]) ? $value : $matches[1];
}
return $host;
}
Ex)
$url = "http://dvlp.tistory.com/1";
echo getHostName($url);
output : tistory.com
|
|
̵̧ : 422 |
̵̧
¸ñ·Ï
|
|