domainvalidity / php-domain-validator
Light PHP package to validate domains.
Installs: 4 563
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^8.1.0
Requires (Dev)
- pestphp/pest: ^2.31
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.8
- symfony/var-dumper: ^7.0
README
Doma(in)Validity PHP package.
Light PHP package to validate domains.
Doma(in)Validity was born because I found myself searching online about how to check if a domain was valid. I always ended up using regular expressions that were too complex to account for several scenarios (mainly the TLD having different formats), it was just a pain in the butt because I always had to go back to that code to fix the regex to account for an edge case that I didn't think about.
Requirements
- PHP >= 8.1.0
Installation
You can install the package via composer:
composer require domainvalidity/php-domain-validator
Usage
use DomainValidity\Factory; $contents = file_get_contents('https://publicsuffix.org/list/public_suffix_list.dat'); $validator = Factory::make($contents); $host = $validator->validate('www.domainvalidity.dev');
Note: You should cache the contents of the public suffix list and download them no more than once per day, as it is not updated more than a few times per week; more frequent downloading is pointless.