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