iamcal/ip-parser

IPv4 & IPv6 parser

Maintainers

Package info

github.com/iamcal/php-ip-parser

pkg:composer/iamcal/ip-parser

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 1

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

This package is auto-updated.

Last update: 2026-03-06 03:40:37 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.