iamcal / ip-parser
IPv4 & IPv6 parser
v1.0.0
2021-04-21 17:12 UTC
Requires (Dev)
- php-coveralls/php-coveralls: ~1.0
- phpunit/phpunit: ~4.8
README
This simple PHP library is based on a twitter thread that became a blog post about parsing IP addresses.
Usage
$input = "1.2.3.4";
$parser = new iamcal\IPParser();
$out = $parser->parse($input);
The single public method, ->parse()
, takes a string and returns an array with two keys:
Array
(
[type] => ipv4
[canonical] => 1.2.3.4
)
The type
will either be "ipv4"
or "ipv6"
, while the canonical
key will contain a canonicalized version of the IP.
Invalid IPs will throw a catchable exception.