How to remove www and validate a valid domain name.
Valid Domain
domain.com
subdomain.domain.com
sub-domain.domain.com
Invalid Domain
www.domain.com
www.subdomain.domain.com
http://www.domain.com/
http://www.subdomain.com/
www.domain.com/folder/
How the code?
$domain ='www.domain.com/folder/';
if() {
// validate here
}
First, manually strip out the www. then just make sure it is in the form domain.tld or something.domain.tld
$domain = str_replace('www.','',$domain);if(preg_match('/([a-zA-Z0-9\-_]+\.)?[a-zA-Z0-9\-_]+\.[a-zA-Z]{2,5}/',$domain))//valid domain