iamcal/ip-parser

IPv4 & IPv6 parser

v1.0.0 2021-04-21 17:12 UTC

This package is auto-updated.

Last update: 2024-10-06 00:15:31 UTC


README

Build Status Coverage Status Latest Stable Version

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.