Horje

Tips (Total 3)


# Tips-1) How to count domain length in PHP

Output is correct. when input is http://test.google.co.uk value of parse_url('http://test.google.co.uk')['host'] is http://test.google.co.uk. When you will exploce this string on dot first element of array will be test and its length is 4.

To get google instead of test you need to replace subdomain with nothing as you did in your first example or take the second element in exploded string. E.g:

How to extract Domain length in PHP

Start your code here.
index.php
Example: HTML
<?php
$url    = 'http://test.google.co.uk';    
$info   = parse_url($url);    
$pieces = explode(".", $info['host']); 
$len    = strlen($pieces[1]); // returns character length of google = 6
echo $len;
?>

# Tips-2) How to get domain extension from php string

Use parse_url(). Something like:

How to show Domain Extension from PHP String

Try following codes.
index.html
Example: HTML
<?php
$host = parse_url('http://www.google.co.uk/test.html');
preg_match('/(.*?)((\.co)?.[a-z]{2,4})$/i', $host['host'], $m);

$ext = isset($m[2]) ? $m[2]: '';
echo $ext; ?>

# Tips-3) How to get Domain http request info in PHP

To retrieve all request headers using the getallheaders() function in PHP, you can follow these steps:

How to extract php domain http request

Follow the Example.
index.php
Example: PHP
<?php
$all_headers = getallheaders();
foreach ($all_headers as $name => $value) {
   echo "$name: $value";
}
?>

Output should be:

How to extract php domain http request