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" } |
More Related Posts
- [2016/05/19] Check if a String Contains Multiple Wo...
- [2016/06/04] Check if a Number is Multiple of Anoth...
- [2016/06/07] How to Get File Extension in PHP
- [2016/05/20] Turn Off Expose_PHP (Hide X-Powered-By...
- [2016/05/26] How to Increase PHP Memory Limit
- [2016/05/25] Disable PHP Notice: Undefined variable...
- [2016/05/19] Validate Value as Integer in PHP
- [2016/05/19] Remove Non-Alphanumeric Characters fro...