How To Get Free Tld Domain?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.