Return to Snippet

Revision: 39565
at January 18, 2011 11:25 by ashworthconsulting


Initial Code
<?php
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',
    "http://www.php.net/index.html", $matches);
$host = $matches[1];

// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
?>

Initial URL

                                

Initial Description

                                

Initial Title
Getting the domain name out of a URL

Initial Tags

                                

Initial Language
PHP