How to remove www and confirm 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 is the code?
$domain ='www.domain.com/folder/'; if() { // validate here }
Manually delete www first. then just make sure it is in the form of 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
Take a look at the http://framework.zend.com/apidoc/core/Zend_Validate/Zend_Validate_Hostname.html ( Zend_Validate_Hostname) class. I think you can use it outside of the Zend Framework with little tweaking.
Zend_Validate_Hostname
$url = "http://stackoverflow.com/"; if (preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $url)) { echo "Your url is ok."; } else { echo "Wrong url."; }
Source: https://habr.com/ru/post/1751951/More articles:isMemberOfClass versus comparing classes with == - classkeeping a list of all local push notifications in iOS 4 - iphonehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1751948/aspnet-mvc-dynamically-set-css-class-to-list-item-based-on-route&usg=ALkJrhgxno6IHJj15UQEiVhfbQz2pZpMywUnderstanding Purple Layouts - phpIs there a good site to search / vote / discuss ruby gems? - ruby | fooobar.comhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1751952/is-there-any-plugins-or-frameworks-or-tools-to-make-the-web-pages-nice-for-a-programmer&usg=ALkJrhgklpUcN28rxcUwveiJBvfjbdtSKwlucene fuzzy search lazy? - luceneAn error occurred while trying to compile the latex document. Where can I find the report output file? - compilationWhy can't Google Reader detect feed for website? - rssPHP or ASP, what should I stick to? - phpAll Articles