itcore TOP プログラムパーツ

uIpZero ゼロ埋めしたIPを返す。192.168.0.1 → 192.168.000.001 | itcore 2017年

PHP関数

<?php include_once "uStr0.func"; ?>
<?php
//ゼロ埋めしたIPを返す。192.168.0.1 → 192.168.000.001
function uIpZero($ip) {
    $ips = explode(".", $ip);
    $ip0 = uStr0($ips[0], 3) . ".";
    $ip0 .= uStr0($ips[1], 3) . ".";
    $ip0 .= uStr0($ips[2], 3) . ".";
    $ip0 .= uStr0($ips[3], 3);
    return $ip0;
}
?>

単体テスト 実行

<?php include "uIpZero.func"; ?>
<?php
  $ip = "192.168.0.1"; $ret = uIpZero($ip);echo "ip=$ip ret=$ret<br>\n";
  $ip = "0.1.2.3"; $ret = uIpZero($ip);echo "ip=$ip ret=$ret<br>\n";
?>

<?php include "uJsClose.func"; print(uJsClose()); // 閉じるボタン ?>