|
|
|
Here gives a example to extract name without extension from an url |
<?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
?>
Category: | Web Tutorial |
Sub Category: | PHP Extract Tutorial |
Uploaded by: | Admin |