PHP Get domain name from full URL with parameters

Today, We want to share with you PHP Get domain name from full URL with parameters.In this post we will show you php get full url with parameters, hear for php get domain without subdomain we will give you demo and example for implement.In this post, we will learn about How to Get Domain Name from URL in PHP with an example.

PHP Get domain name from full URL with parameters

There are the Following The simple About PHP Get domain name from full URL with parameters Full Information With Example and source code.

Also Read This πŸ‘‰   jquery multiple Image Upload with preview and Delete using PHP

As I will cover this Post with live Working example to develop php get domain name with https, so the some major get url after domain php for this example is following below.

Free Live Chat for Any Issue

Get domain name from full URL Example

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

echo fetchLiveDomain("https://www.pakainfo.com"); // outputs 'pakainfo.com'
echo fetchLiveDomain("http://www.pakainfo.com"); // outputs 'pakainfo.com'
echo fetchLiveDomain("http://mail.pakainfo.co.uk"); // outputs 'pakainfo.co.uk'

PHP – get domain name from URL

Get the full URL in PHP

<?php 
// php get domain name with https. 
 
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') 
    $fullurl = "https"; 
else
    $fullurl = "http"; 
  
// Now put the default URL characters using PHP. 
$fullurl .= "://"; 
  
// put the host(domain name, ip) to the URL using PHP. 
$fullurl .= $_SERVER['HTTP_HOST']; 
  
// put the requested resource location to the URL using PHP
$fullurl .= $_SERVER['REQUEST_URI']; 
      
// display the fullurl 
echo $fullurl; 
?> 

//https://www.pakainfo.com/

Get The Current Page URL with PHP $_SERVER

<?php 
// Get The Current Page URL with PHP $_SERVER. 
  
$fullurl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 
                "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .  
                $_SERVER['REQUEST_URI']; 
  
echo $fullurl; 
?> 

Angular 6 CRUD Operations Application Tutorials

Read :

Also Read This πŸ‘‰   How to Retrieve Domain Name from URL in PHP?

Summary

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

I hope you get an idea about PHP Get domain name from full URL with parameters.
I would like to have feedback on my Pakainfo.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.