Rating: 1 Star2 Stars3 Stars4 Stars5 Stars

How To Get Domain, Subdomain, TLD, CTLD & Path from URL In PHP

Recently for one of our project i was supposed to get Country Name, Sub Domain, Top Level Domain (TLD), Country Level Domain (CTLD) and Path from the given URL which will further be inserted into the database. Many functions which we used to test different scenarios, failed to perform on some logic or another. While searching for a better approach i ended up finding one answer in Stackoverflow by “Whatever Kitchen” which did the job perfectly. Here is a modified version of the function

Code Explaination

This function expects three parameters:

  1. URL
  2. Get What (default is everything)
  3. Output Format (default is an Array)

Calling the Function In Your App

You can call this function like url_information($myUrl, 'ALL', 'array'); within your application by sending those 3 parameters. Default output format will be an Array. Following are examples of how this function can be called to get the value.

I hope this function will help you get the information you need by providing proper parameters. Please feel free to suggest any further enhancements if you like. Subscribe our RSS to receive latest updates.

Related Posts


Integrating BrainTree Payment Gateway With PHP

How to create XML with PHP Mysql

How To Create XML With PHP MySQL

RBS WorldPay Integration With PHP

Integrating RBS WorldPay XML Direct Method with PHP

wordpress Posting Content via XML RPC

WordPress XMLRPC – Posting Content From Outside WordPress Admin Panel

  • Hey! This code is legit, thanks very much for posting. However I’ve dumped it into and it errors out of the box. Are you sure everything is setup right? I’ll be hacking away at it anywho! thanks again.