PHP Domain Parser: Domain\URL Parser PHP Library

PHP Domain Parser is an open source Public Suffix List based domain parser PHP library. It is actively developed and it can effectively parse URLs to extract the subdomain, registrable domain, public suffix (TLD), query string, and much more. PHP Domain Parser is very useful to get the real domain name, the TLD or only the subdomain of a full URL.

Here is an example usage:

require_once '../vendor/autoload.php';
$pslManager = new Pdp\PublicSuffixListManager();
$parser = new Pdp\Parser($pslManager->getList());
$host = 'http://user:pass@www.pref.okinawa.jp:8080/path/to/page.html?query=string#fragment';
$url = $parser->parseUrl($host);
var_dump($url);

This is what you get as output:

class Pdp\Uri\Url#6 (8) {
    private $scheme =>
    string(4) "http"
    private $host =>
    class Pdp\Uri\Url\Host#5 (3) {
        private $subdomain =>
        string(3) "www"
        private $registrableDomain =>
        string(15) "pref.okinawa.jp"
        private $publicSuffix =>
        string(10) "okinawa.jp"
    }
    private $port =>
    int(8080)
    private $user =>
    string(4) "user"
    private $pass =>
    string(4) "pass"
    private $path =>
    string(18) "/path/to/page.html"
    private $query =>
    string(12) "query=string"
    private $fragment =>
    string(8) "fragment"
}

Visit Homepage

More Related Posts