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



Related Articles
How to count domain length in PHP PHP Domain Tutorial
How to get domain extension from php string PHP Domain Tutorial
How to get Domain http request info in PHP PHP Domain Tutorial

Single Articles
How to extract Domain length in PHPPHP Domain Tutorial

Read Full::
PHP Domain Tutorial
Category:
Web Tutorial
Sub Category:
PHP Domain Tutorial
Uploaded:
4 months ago
Uploaded by:
Admin
Views:
3
Ref on:
View



Share on: