Horje
How to extract only name from domain in PHP

Here gives a example to extract name without extension from an url


Full completed code for getting only name from domain url

Just create a file index.php and insert following code.
index.php
Example: PHP
<?php
function get_domain($url)
{
  $pieces = parse_url($url);
  $domain = isset($pieces['host']) ? $pieces['host'] : $pieces['path'];
  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;
}
?>
<?php
$domain_name = 'https://horje.com/learn/511/how-to-set-html-autofocus-attribute-in-input';
$domain_name = get_domain($domain_name);
$domain_name = pathinfo($domain_name, PATHINFO_FILENAME); 

echo $domain_name;
// Result: horje
?>

Output should be:

Full completed code for getting only name from domain url





Related Articles
How to extract Domain Name from Full URL in PHP PHP Extract Tutorial
How to extract only name from domain in PHP PHP Extract Tutorial
How to extract All url from a single page by PHP PHP Extract Tutorial
How to get first Five Line from CSV File PHP Extract Tutorial
How to get first 100 records from a csv file in PHP PHP Extract Tutorial
How to get meta Tag PHP Extract Tutorial
How to get title description image and multiple images from URL PHP Extract Tutorial
How to read a txt file from a zip remote URL PHP Extract Tutorial
How to extract all url from a html single page in PHP PHP Extract Tutorial

Single Articles
Full completed code for getting only name from domain urlPHP Extract Tutorial

Read Full:
PHP Extract Tutorial
Category:
Web Tutorial
Sub Category:
PHP Extract Tutorial
Uploaded:
10 months ago
Uploaded by:
Admin
Views:
32



Share on: