Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>there's a few steps you can take to get a clean url.</p> <p>Firstly you need to make sure there is a protocol to make parse_url work correctly so you can do:</p> <pre><code>//Make sure it has a protocol if(substr($url,0,7) != 'http://' || substr($url,0,8) != 'https://') { $url = 'http://' . $url; } </code></pre> <p>Now we run it through <code>parse_url()</code></p> <pre><code>$segments = parse_url($url); </code></pre> <p>But this is where it get's complicated because the way domain names are constructed is that you can have 1,2,3,4,5,6 .. .domain levels, meaning that you cannot detect the domain name from all urls, you have to have a pre compiled list of tld's to check the last portion of the domain, so you then can extract that leaving the website's domain.</p> <p>There is a list available here : <a href="http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1" rel="nofollow">http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1</a></p> <p>But you would be better of parsing this list into mysql and then select the row where the tld matches the left side of the domain string.</p> <p>Then you order by length and limit to 1, if this is found then you can do something like:</p> <pre><code>$db_found_tld = 'co.uk'; $domain = 'a.b.c.domain.co.uk'; $domain_name = substr($domain,0 - strlen($db_found_tld)); </code></pre> <p>This would leave <code>a.b.c.domain</code>, so you have removed the tld, now the domain name would be extracted like so:</p> <pre><code>$parts = explode($domain_name); $base_domain = $parts[count($parts) - 1]; </code></pre> <p>now you have <code>domain</code>.</p> <p>this seems very lengthy but I hope now you know that its not easy to get just the domain name without tld or sub domains.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload