承接 silvarcode/domain-parser 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

silvarcode/domain-parser

最新稳定版本:1.0.0

Composer 安装命令:

composer require silvarcode/domain-parser

包简介

A high-performance PHP library for validating and parsing domain names using the Public Suffix List.

README 文档

README

License Release

SilvarCode Domain Parser is a robust and efficient PHP library for parsing and validating domain names using the Public Suffix List.

It supports complex TLD structures and wildcard suffixes, making it suitable for both general-purpose and enterprise-level domain validation.

Features

  • ✅ Parses registrable domains from full hostnames
  • 🔍 Extracts subdomain and subdomain hierarchy
  • 🌐 Supports wildcard and multi-level TLDs (e.g., *.k12.ak.us, *.sch.uk)
  • 📥 Uses the official Public Suffix List
  • 🧠 Configurable in-memory caching
  • 🛠️ Custom suffix injection for internal/private networks

Requirements

  • PHP 8.2 or higher

Installation

composer require silvarcode/domain-parser

Usage

Instantiating the DomainParser

You can create a new instance of the DomainParser class with optional memory caching enabled and provide custom suffixes if needed:

Parameter Type Description
memoryCache bool Whether to load the suffix set into memory for improved performance
suffixSet array An optional list of custom suffixes (e.g., for internal domains)

Example

use SilvarCode\DomainParser\Parser\DomainParser;

// Instantiate parser with memory cache enabled
$parser = new DomainParser(true);

// Instantiate parser with memory cache and custom suffixes
$parser2 = new DomainParser(true, ['com.internal']);

$checkHost1 = 'sub2.sub1.example.com';
$checkHost2 = 'sub2.sub1.example.com.internal';

// Show parsing results for checkHost1 using $parser
$parser->showResult([
    'tld' => $parser->tld($checkHost1),
    'domain' => $parser->getRegistrableDomain($checkHost1),
    'subdomain' => $parser->getSubdomain($checkHost1),
    'subdomains' => $parser->getSubdomains($checkHost1),
]);

// Show parsing results for checkHost2 using $parser
$parser->showResult([
    'tld' => $parser->tld($checkHost2),
    'domain' => $parser->getRegistrableDomain($checkHost2),
    'subdomain' => $parser->getSubdomain($checkHost2),
    'subdomains' => $parser->getSubdomains($checkHost2),
]);

// Show parsing results for checkHost2 using $parser2 with custom suffixes
$parser2->showResult([
    'tld' => $parser2->tld($checkHost2),
    'domain' => $parser2->getRegistrableDomain($checkHost2),
    'subdomain' => $parser2->getSubdomain($checkHost2),
    'subdomains' => $parser2->getSubdomains($checkHost2),
]);

💻 Command-Line Usage (via Composer)

If you’ve defined the CLI entry point in composer.json like this:

"bin": [
  "bin/check.php"
],
"scripts": {
  "check-domain": "bin/check.php"
}

You can run domain checks directly from the terminal:

composer check-domain sub2.sub1.example.com

Output:

Host: sub2.sub1.example.com
Domain: example.com
Subdomain: sub2
Subdomains:
  - sub2
  - sub1

Learn More!

We’ve published an in-depth blog post on our website that covers the design, features, and practical usage of the SilvarCode Domain Parser.
It’s a great resource if you want to understand the package better or see real-world examples.

👉 Read the full blog post here

Feel free to share your feedback or questions in the GitHub issues or discussions!

License

MIT License
© 2025 SILVARCODE LTD
Author: Marcus Ribeiro (mds@silvarcode.com)

This software is provided "as is", without any warranty of any kind whatsoever.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-07