silvarcode/domain-parser
Composer 安装命令:
composer require silvarcode/domain-parser
包简介
A high-performance PHP library for validating and parsing domain names using the Public Suffix List.
关键字:
README 文档
README
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.
silvarcode/domain-parser 适用场景与选型建议
silvarcode/domain-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 409 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「parser」 「url」 「domain」 「subdomain」 「tld」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 silvarcode/domain-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 silvarcode/domain-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 silvarcode/domain-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Easy URL rewrites in your Laravel application
An MT940 bank statement parser for PHP
A Laravel helper to detect if the current route/path is active.
Laravel integration for the jsonapi.org parser
Provides a service and twig extension for getting short urls like http://your.host/~short
统计信息
- 总下载量: 409
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-07