iamcal / ip-parser
IPv4 & IPv6 parser
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
pkg:composer/iamcal/ip-parser
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.