Is there any predefined function or short method to convert shortest IPv6 address to longest. Below is the one which I'm using. Please do let me know the better one. Thanks in advance.
$shrtIPv6 = "2001:100:e20::1";
$pieces = explode(":", $shrtIPv6);
foreach($pieces as $piece)
{
$zerosuff = str_pad($piece, 4, '0', STR_PAD_LEFT);
$array1[] .= $zerosuff;
}
if(count($pieces)<8){
$myarray = array("0000","0000","0000","0000","0000","0000","0000");
$last = array_slice($array1, -1);
$array1 = array_slice($array1,0,-1);
$both = array_replace($myarray,$array1);
$fin = array_merge($both,$last);
echo implode(":",$fin);
}