Posted inProgramming / php

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.

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.

Get domain name from full URL Example

function fetchLiveDomain($url){
    $parts = parse_url($url);
    $domain = isset($parts['host']) ? $parts['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 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

 

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

Get The Current Page URL with PHP $_SERVER

 
Angular 6 CRUD Operations Application Tutorials

How to get the current domain name using PHP?

To get the current domain name using PHP, you can use the $_SERVER superglobal variable and access its SERVER_NAME key. Here’s an example code snippet:

$current_domain = $_SERVER['SERVER_NAME'];
echo $current_domain;

This code will output the current domain name in the browser. Keep in mind that the SERVER_NAME key may not be set in all environments, so it’s a good practice to check if it’s available before using it.

Read :

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype