Hi,
I need to have [ www. ] disregarded while matching a domain name.
For example, all the below should be valid.
Learn Web Design & Development with SitePoint tutorials, courses and books - HTML, CSS, JavaScript, PHP, Responsive Web Design
Learn Web Design & Development with SitePoint tutorials, courses and books - HTML, CSS, JavaScript, PHP, Responsive Web Design
http://sitepoint.com
https://sitepoint.com
What can be the accurate regular expression?
#^http[s]?://[www\.]?sitepoint\.com/# would not work for www-version of the domain name.
Thank you.
Thank you for your response.
I modified + into ? and it worked as I wanted.
$pattern = "#^http[s]?://(?:[w]{3}+\\.)?{$server_name}#";
https, http, www. version, no www. version are all valid: 4 checks with this.
force
July 2, 2010, 12:51am
3
http[s]?://(?:[0-9a-zA-Z-_]+\\.)+(?:[a-zA-Z]{2,5})
I usually use something like this for valid domain detection. It will detect any subdomain or chain of subdomains, and any TLD (the TLDs are not pre-defined since new ones do get added)
Or, if you want to just remove the “www” from the string, I’ve used this:
$domain = str_replace('www.', '', $domain);