<?php
error_reporting(E_ALL);
function ip6ptrtoip6($arpa) {
$mainptr = substr($arpa, 0, strlen($arpa)-9);
$pieces = array_reverse(explode(".",$mainptr));
$count=count($pieces);
$hex = implode("",$pieces);
$hex=str_pad($hex,32,'0');
$ipbin = pack('H*', $hex);
$ipv6addr = inet_ntop($ipbin);
if($count<32) {
$ipv6addr .= '0/' . $count*4;
}
// dump_nice essentially captures the output of var_dump into a string so I can
// at the bottom of the page.
var_dump(array($arpa,$hex,error_get_last(),$ipv6addr));
return $ipv6addr;
}
ip6ptrtoip6("0.7.1.2.2.0.a.2.ip6.arpa");