How to Retrieve Domain Name from URL in PHP?

Today, We want to share with you How to Retrieve Domain Name from URL in PHP?.In this post we will show you How to get domain name from URL with PHP?, hear for php Retrieve domain name with https we will give you demo and example for implement.In this post, we will learn about How to get domain name from URL in bash shell script with an example.

How to Retrieve Domain Name from URL in PHP?

There are the Following The simple About How to Retrieve Domain Name from URL in PHP? Full Information With Example and source code.

As I will cover this Post with live Working example to develop A PHP Function That Gets The Domain Name From A URL Or String, so the how to get only domain name from given URL in php Laravel is used for this example is following below.

How to get a domian name from the URL in PHP?

If we want to get the your domain name from a url, this best Article might be helpful for we.

$my_url = 'http://google-rokers.com/articles/free-download-tamil-rokers-new-movie-upcomming-list-2022-2021-2020';
$uri_parse = parse_url($my_url);

echo $uri_parse['host'];  // prints 'google-rokers.com'

How to get the base domain name from an URL using PHP?


php get domain name with https Function

function fetchDomainName($my_url){
    $uri_parse = parse_url($my_url);
    $domain = isset($uri_parse['host']) ? $uri_parse['host'] : '';
    if(preg_match('/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)){
        return $regs['domain'];
    }
    return FALSE;
}

echo fetchDomainName("https://www.pakainfo.com"); // outputs 'pakainfo.com'
echo fetchDomainName("http://www.pakainfo.com"); // outputs 'pakainfo.com'
echo fetchDomainName("http://mail.pakainfo.co.uk"); // outputs 'pakainfo.co.uk'
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about php get domain without subdomain.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment