定制 ivankristianto/tld-extract 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ivankristianto/tld-extract

Composer 安装命令:

composer require ivankristianto/tld-extract

包简介

TLDExtract package forked from layershifter/tld-extract to support PHP 5.4

README 文档

README

Latest Stable Version Build Status Total Downloads

Scrutinizer Code Quality Code Coverage

This is a forked from layershifter/tld-extract to support PHP 5.4.0.

To support PHP 5.4.0 please use version ^0.2.2 or use the composer command below:

composer require ivankristianto/tld-extract "^0.2.2"

TLDExtract accurately separates the gTLD or ccTLD (generic or country code top-level domain) from the registered domain and subdomains of a URL. For example, say you want just the 'google' part of 'http://www.google.com'.

Everybody gets this wrong. Splitting on the '.' and taking the last 2 elements goes a long way only if you're thinking of simple e.g. .com domains. Think parsing http://forums.bbc.co.uk for example: the naive splitting method above will give you 'co' as the domain and 'uk' as the TLD, instead of 'bbc' and 'co.uk' respectively.

Extract on the other hand knows what all gTLDs and ccTLDs look like by looking up the currently living ones according to the Public Suffix List. So, given a URL, it knows its subdomain from its domain, and its domain from its country code.

$result = Extract::get('http://forums.news.cnn.com/');
var_dump($result);

object(LayerShifter\TLDExtract\Result)#34 (3) {
  ["subdomain":"LayerShifter\TLDExtract\Result":private]=>
  string(11) "forums.news"
  ["domain":"LayerShifter\TLDExtract\Result":private]=>
  string(3) "cnn"
  ["tld":"LayerShifter\TLDExtract\Result":private]=>
  string(3) "com"
}

Result implements ArrayAccess interface, so you simple can access to its result.

var_dump($result['subdomain']);
string(11) "forums.news"

var_dump($result['domain']);
string(3) "cnn"

var_dump($result['tld']);
string(3) "com"

Also you can simply convert result to JSON.

var_dump($result->toJson());
string(54) "{"subdomain":"forums.news","domain":"cnn","tld":"com"}"

This package based on code from w-shadow which is port of Python module.

Compatible PHP versions

  • PHP 5.4
  • PHP 5.5
  • PHP 5.6
  • PHP 7
  • HHVM

Installation

Latest release via Composer:

$ composer require layershifter/tld-extract

Note About Advanced Usage & Caching

Advanced usage

For overriding object that will be returned in result you can create own class that implements \LayerShifter\TLDExtract\Interfaces\ResultInterface.

For example:

class OwnResult implements \LayerShifter\TLDExtract\Interfaces\ResultInterface {
}

Extract::setResultClass('OwnResult');

Caching

By default TLDExtract downloads TLD list from publicsuffix.org, caches it and never update.

You can override this behavior via setting $fetch to true:

Extract::setFetch(true);

Also, you can manually update TLD cache by calling method (recommended):

Extract::updateCache();

This method returns boolean that indicates processes result.

By default cache file will be stored in /path/to/TLDExtract/cache/.tld_set, you can set file for cache by calling:

Extract::setCacheFile('/path/to/your/dir/cache.file');

License

This project is open-sourced software licensed under the MIT License.

See the LICENSE file for more information.

统计信息

  • 总下载量: 9.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 32
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-08-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固