<?php
function normalizeIP( $ip ) {
$ip = inet_pton( $ip );
}
$out = '';
for( $i = 0; $i < 16; ) {
if( $i && $i % 2 == 0 ) $out .= ':';
}
return $out;
}
echo normalizeIP( '192.168.0.1' )."\n";
echo normalizeIP( '208.67.222.222' )."\n";
echo normalizeIP( 'dd::caa8:0002' )."\n";
echo normalizeIP( '::ffff:192.168.0.1' )."\n";
?>
PD9waHAKICAgZnVuY3Rpb24gbm9ybWFsaXplSVAoICRpcCApIHsKICAgICAgJGlwID0gaW5ldF9wdG9uKCAkaXAgKTsKICAgICAgaWYoIHN0cmxlbiggJGlwICkgPCA1ICkgewogICAgICAgICAkaXAgPSBjaHIoIDI1NSApLmNociggMjU1ICkuc3RyX3BhZCggJGlwLCA0LCBjaHIoIDAgKSwgU1RSX1BBRF9MRUZUICk7CiAgICAgIH0KICAgICAgJGlwID0gc3RyX3NwbGl0KCBzdHJfcGFkKCAkaXAsIDE2LCBjaHIoIDAgKSwgU1RSX1BBRF9MRUZUICkgKTsKICAgICAgJG91dCA9ICcnOwogICAgICBmb3IoICRpID0gMDsgJGkgPCAxNjsgKSB7CiAgICAgICAgIGlmKCAkaSAmJiAkaSAlIDIgPT0gMCApICRvdXQgLj0gJzonOwogICAgICAgICAkb3V0IC49IHN0cl9wYWQoIGRlY2hleCggb3JkKCAkaXBbJGkrK10gKSApLCAyLCAnMCcsIFNUUl9QQURfTEVGVCApOwogICAgICB9CiAgICAgIHJldHVybiAkb3V0OwogICB9CiAgIAogICBlY2hvIG5vcm1hbGl6ZUlQKCAnMTkyLjE2OC4wLjEnICkuIlxuIjsKICAgZWNobyBub3JtYWxpemVJUCggJzIwOC42Ny4yMjIuMjIyJyApLiJcbiI7CiAgIGVjaG8gbm9ybWFsaXplSVAoICdkZDo6Y2FhODowMDAyJyApLiJcbiI7CiAgIGVjaG8gbm9ybWFsaXplSVAoICc6OmZmZmY6MTkyLjE2OC4wLjEnICkuIlxuIjsKPz4K