Get only domain name without tld,www & subdomain in php?
-
I want to get domain name from the full URL without tld, www, subdomain. e.g. if I am having URL like http://www.example.com or http://example.com or http://subdomain.example.com or http://www.example.com.au it should return example How can I get it? I tried parse_url but it returned me the URL with tld & subdomain. Plesae help me. Thanks in advance.
-
Answer:
Without the complete and specific requirement, I can not give you a working solution. But the idea is straightforward: use regular expression to do the matching (based on your criteria) and extraction. something like the following, but I didn't try actually running it: $pattern = '@https?://[a-z]{1,}\.{0,}([a-z]{1,})\.com(\.[a-z]{1,}){0,}@' preg_match($pattern, $s, $matched); print_r($matched); you most likely want to modify the $pattern regex to match your requirements
Zhang Yining at Quora Visit the source
Other answers
As the only reliable source for domain suffixes are the domain registrars, you can't find the subdomain without their knowledge. There is a list with all domain suffixes athttps://publicsuffix.org/. This site also links to a PHP library: https://github.com/jeremykendall/php-domain-parser. via http://stackoverflow.com/a/25548209/514629
Chema GD
Related Q & A:
- Can I domain map without wordpress?Best solution by Webmasters
- How Do You Buy A Domain Name Outright?Best solution by Yahoo! Answers
- How can we protect a domain name and trademark internationally?Best solution by Quora
- How do I get a domain name?Best solution by wikihow.com
- Where to get a domain name?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.