Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Extract the domain name from a URL

/*
Write a function that when given a URL as a string, parses out just the domain 
name and returns it as a string. For example:

  * url = "http://github.com/carbonfive/raygun" -> domain name = "github"
  * url = "http://www.zombie-bites.com"         -> domain name = "zombie-bites"
  * url = "https://www.cnet.com"                -> domain name = cnet"
*/

const domainName = url => {
  let regExp = /http(s)?://|www./gi
  return url.replace(regExp, "").split(".")[0]
}

// With love @kouqhar
Comment

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'
Comment

Get domain name from full URL Example

<?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/
Comment

Get domain name from full URL Example

<?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; 
?>
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongodb.connect is not a function 
Javascript :: how to make your own drop down react native 
Javascript :: javascript hello 
Javascript :: regrex match emails 
Javascript :: p5.js 
Javascript :: jquery download 
Javascript :: jquery get cursor position 
Javascript :: rotate array by d elements javascript 
Javascript :: js sort object properties alphabetically 
Javascript :: open sans font 
Javascript :: reverse json.stringify 
Javascript :: compare two array in javascript 
Javascript :: new Date().toLocaleDateString day 
Javascript :: reverse a string in javascript 
Javascript :: reload page after form submit javascript 
Javascript :: how to get day, month and year javascript 
Javascript :: js queryselector find without attribute 
Javascript :: add webpack to react project tutorial 
Javascript :: vuejs router params 
Javascript :: max value from array in javascript 
Javascript :: how to deep copy an object in javascript 
Javascript :: how to change the first 3 letters from a string toupper case 
Javascript :: Configure the Chrome debugger react 
Javascript :: get results from db and put in javascript array codeigniter 
Javascript :: fs.readdir callback function 
Javascript :: watch file in changes in webpack 
Javascript :: jquery select all checkboxes except disabled 
Javascript :: javascript promise 
Javascript :: each jquery 
Javascript :: ng-if variable is undefined 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =