URLの解析は、PHPだとparse_url を使えば
ある程度できるけど、ドメインだけ抽出するとなると
ちょっとやっかいだったりする
そんなときに便利なのがこれ
https://github.com/layershifter/TLDExtract
composerでインストールしてサクッと使えまーす
1 |
$ composer require layershifter/tld-extract |
例えばこんな感じで使える
1 2 3 4 |
$url = 'https://example.com'; $parse = parse_url($url); $host = $parse["host"]; $tld = tld_extract($host); |