php - get domain name from link with a fast and reliable method -
currently using code domain name (without www. or domain ending .com):
explode('.', $url)[1];
due fact code in loop takes long handle it. furthermore can not "example" http://example.com/asd/asd.asd.html. there another , faster way solve this?
thank answer in advance!
best greetings
use parse_url()
$host = parse_url($url, php_url_host);
php_url_host returns host
further, use regex desired part of host:
$result = preg_match('/^(?:www\.)?([^\.]+)/', $match);
Comments
Post a Comment