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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -