Example 1 — Convert Packed IPv4 Back to Text
Pack 127.0.0.1 with inet_pton(), then unpack it with inet_ntop().
<?php
$packed = inet_pton("127.0.0.1");
echo inet_ntop($packed), PHP_EOL; How It Works
- inet_pton() creates the 4-byte binary form.
- inet_ntop() turns that binary back into dotted text.
- The printed value matches the original address.
- This round-trip is the usual teaching demo for both functions.

