当前位置: 首页>>代码示例>>PHP>>正文


PHP zeropad函数代码示例

本文整理汇总了PHP中zeropad函数的典型用法代码示例。如果您正苦于以下问题:PHP zeropad函数的具体用法?PHP zeropad怎么用?PHP zeropad使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zeropad函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDates

function getDates($dayofmonth, $months = 0)
{
    $dayofmonth = zeropad($dayofmonth);
    $year = date('Y');
    $month = date('m');
    if (date('d') > $dayofmonth) {
        // Billing day is past, so it is next month
        $date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
        $date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
        date_add($date_end, date_interval_create_from_date_string('1 month'));
    } else {
        // Billing day will happen this month, therefore started last month
        $date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
        $date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
        date_sub($date_start, date_interval_create_from_date_string('1 month'));
    }
    if ($months > 0) {
        date_sub($date_start, date_interval_create_from_date_string($months . ' month'));
        date_sub($date_end, date_interval_create_from_date_string($months . ' month'));
    }
    // date_sub($date_start, date_interval_create_from_date_string('1 month'));
    date_sub($date_end, date_interval_create_from_date_string('1 day'));
    $date_from = date_format($date_start, 'Ymd') . '000000';
    $date_to = date_format($date_end, 'Ymd') . '235959';
    date_sub($date_start, date_interval_create_from_date_string('1 month'));
    date_sub($date_end, date_interval_create_from_date_string('1 month'));
    $last_from = date_format($date_start, 'Ymd') . '000000';
    $last_to = date_format($date_end, 'Ymd') . '235959';
    $return = array();
    $return['0'] = $date_from;
    $return['1'] = $date_to;
    $return['2'] = $last_from;
    $return['3'] = $last_to;
    return $return;
}
开发者ID:Tatermen,项目名称:librenms,代码行数:35,代码来源:billing.php

示例2: snmp_cache_cip

function snmp_cache_cip($oid, $device, $array, $mib = 0)
{
    global $config;
    $cmd = ($device['snmpver'] == 'v1' ? $config['snmpwalk'] : $config['snmpbulkwalk']) . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . ":" . $device['port'] . " ";
    if ($mib) {
        $cmd .= "-m {$mib} ";
    }
    $cmd .= $oid;
    $data = trim(shell_exec($cmd));
    $device_id = $device['device_id'];
    #echo("Caching: $oid\n");
    foreach (explode("\n", $data) as $entry) {
        list($this_oid, $this_value) = split("=", $entry);
        $this_oid = trim($this_oid);
        $this_value = trim($this_value);
        $this_oid = substr($this_oid, 30);
        list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode(".", $this_oid);
        $h_a = zeropad(dechex($a));
        $h_b = zeropad(dechex($b));
        $h_c = zeropad(dechex($c));
        $h_d = zeropad(dechex($d));
        $h_e = zeropad(dechex($e));
        $h_f = zeropad(dechex($f));
        $mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}";
        if ($dir == "1") {
            $dir = "input";
        } elseif ($dir == "2") {
            $dir = "output";
        }
        if ($mac && $dir) {
            $array[$device_id][$ifIndex][$mac][$oid][$dir] = $this_value;
        }
    }
    return $array;
}
开发者ID:kyrisu,项目名称:observernms,代码行数:35,代码来源:snmp.inc.php

示例3: getDates

function getDates($dayofmonth, $months = 0)
{
    $dayofmonth = zeropad($dayofmonth);
    $year = date('Y');
    $month = date('m');
    if (date('d') >= $dayofmonth) {
        $date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
        $date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
        date_add($date_end, date_interval_create_from_date_string('1 月'));
    } else {
        // Billing day will happen this month, therefore started last month
        $date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
        $date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
        date_sub($date_start, date_interval_create_from_date_string('1 月'));
    }
    if ($months > 0) {
        date_sub($date_start, date_interval_create_from_date_string($months . ' 月'));
        date_sub($date_end, date_interval_create_from_date_string($months . ' 月'));
    }
    #  date_sub($date_start, date_interval_create_from_date_string('1 月'));
    date_sub($date_end, date_interval_create_from_date_string('1 天'));
    $date_from = date_format($date_start, 'Ymd') . "000000";
    $date_to = date_format($date_end, 'Ymd') . "235959";
    date_sub($date_start, date_interval_create_from_date_string('1 月'));
    date_sub($date_end, date_interval_create_from_date_string('1 月'));
    $last_from = date_format($date_start, 'Ymd') . "000000";
    $last_to = date_format($date_end, 'Ymd') . "235959";
    $return['0'] = $date_from;
    $return['1'] = $date_to;
    $return['2'] = $last_from;
    $return['3'] = $last_to;
    return $return;
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:33,代码来源:billing.inc.php

示例4: getHEXRGB

function getHEXRGB($string)
{
    $matches = null;
    $returnValue = preg_match('/rgba?\\(\\s*(?<red>[0-9A-F]{1,3})\\s*,\\s*(?<green>[0-9A-F]{1,3})\\s*,\\s*(?<blue>[0-9A-F]{1,3})/is', $string, $matches);
    if ($returnValue) {
        return zeropad(dechex(intval($matches["red"])), 2) . zeropad(dechex(intval($matches["green"])), 2) . zeropad(dechex(intval($matches["blue"])), 2);
    }
    return trim($string, "#");
}
开发者ID:zakaria340,项目名称:critique,代码行数:9,代码来源:front.php

示例5: snmpwalk_cache_cip

function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0)
{
    global $config, $debug;
    $timeout = prep_snmp_setting($device, 'timeout');
    $retries = prep_snmp_setting($device, 'retries');
    if (!isset($device['transport'])) {
        $device['transport'] = 'udp';
    }
    if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) {
        $snmpcommand = $config['snmpwalk'];
    } else {
        $snmpcommand = $config['snmpbulkwalk'];
    }
    $cmd = $snmpcommand;
    $cmd .= snmp_gen_auth($device);
    $cmd .= ' -O snQ';
    if ($mib) {
        $cmd .= " -m {$mib}";
    }
    $cmd .= mibdir(null);
    $cmd .= isset($timeout) ? ' -t ' . $timeout : '';
    $cmd .= isset($retries) ? ' -r ' . $retries : '';
    $cmd .= ' ' . $device['transport'] . ':' . $device['hostname'] . ':' . $device['port'] . ' ' . $oid;
    if (!$debug) {
        $cmd .= ' 2>/dev/null';
    }
    $data = trim(external_exec($cmd));
    // echo("Caching: $oid\n");
    foreach (explode("\n", $data) as $entry) {
        list($this_oid, $this_value) = preg_split('/=/', $entry);
        $this_oid = trim($this_oid);
        $this_value = trim($this_value);
        $this_oid = substr($this_oid, 30);
        list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode('.', $this_oid);
        $h_a = zeropad(dechex($a));
        $h_b = zeropad(dechex($b));
        $h_c = zeropad(dechex($c));
        $h_d = zeropad(dechex($d));
        $h_e = zeropad(dechex($e));
        $h_f = zeropad(dechex($f));
        $mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}";
        if ($dir == '1') {
            $dir = 'input';
        } else {
            if ($dir == '2') {
                $dir = 'output';
            }
        }
        if ($mac && $dir) {
            $array[$ifIndex][$mac][$oid][$dir] = $this_value;
        }
    }
    //end foreach
    return $array;
}
开发者ID:JamesonFinney,项目名称:librenms,代码行数:55,代码来源:snmp.inc.php

示例6: snmpwalk_cache_oid

// Copyright (c) 1986-2011 by Cisco Systems, Inc.
// Compiled Thu 22-Dec-11 00:46 by prod_rel_team
// mtxrNeighborPlatform.1 = STRING: cisco WS-C2960G-48TC-L
// mtxrNeighborIdentity.1 = STRING: switch.example.com
// mtxrNeighborSoftwareID.1 = STRING:
// mtxrNeighborInterfaceID.1 = INTEGER: 2
$mtxr_array = snmpwalk_cache_oid($device, "mtxrNeighbor", array(), "MIKROTIK-MIB", NULL, OBS_SNMP_ALL | OBS_SNMP_CONCAT);
if ($mtxr_array) {
    if (OBS_DEBUG > 1) {
        print_vars($mtxr_array);
    }
    foreach ($mtxr_array as $key => $entry) {
        // Need to straighten out the MAC first for use later. Mikrotik does not pad the numbers! (i.e. 0:12:23:3:5c:6b)
        // FIXME move this to a smarter function?
        list($a, $b, $c, $d, $e, $f) = explode(':', $entry['mtxrNeighborMacAddress'], 6);
        $entry['mtxrNeighborMacAddress'] = zeropad($a) . ':' . zeropad($b) . ':' . zeropad($c) . ':' . zeropad($d) . ':' . zeropad($e) . ':' . zeropad($f);
        $ifIndex = $entry['mtxrNeighborInterfaceID'];
        // Get the port using BRIDGE-MIB
        $port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", array($device['device_id'], $ifIndex));
        $remote_device_id = FALSE;
        $remote_port_id = 0;
        if (is_valid_hostname($entry['mtxrNeighborIdentity'])) {
            if (isset($GLOBALS['cache']['discovery-protocols'][$entry['mtxrNeighborIdentity']])) {
                // This hostname already checked, skip discover
                $remote_device_id = $GLOBALS['cache']['discovery-protocols'][$entry['mtxrNeighborIdentity']];
            } else {
                $remote_device = dbFetchRow("SELECT `device_id`, `hostname` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?", array($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborIdentity']));
                $remote_device_id = $remote_device['device_id'];
                // If we don't know this device, try to discover it, as long as it's not matching our exclusion filters
                if (!$remote_device_id && !is_bad_xdp($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborPlatform'])) {
                    $remote_device_id = discover_new_device($entry['mtxrNeighborIdentity'], 'xdp', 'MNDP', $device, $port);
开发者ID:Natolumin,项目名称:observium,代码行数:31,代码来源:mikrotik-mib.inc.php

示例7: testZeropad

 /**
  * @dataProvider providerZeropad
  */
 public function testZeropad($value, $result)
 {
     $this->assertSame($result, zeropad($value));
 }
开发者ID:skive,项目名称:observium,代码行数:7,代码来源:IncludesCommonTest.php

示例8: snmpwalk_cache_cip

function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0)
{
    $cmd = gen_snmpwalk_cmd($device, $oid, ' -OsnQ', $mib);
    $data = trim(external_exec($cmd));
    // echo("Caching: $oid\n");
    foreach (explode("\n", $data) as $entry) {
        list($this_oid, $this_value) = preg_split('/=/', $entry);
        $this_oid = trim($this_oid);
        $this_value = trim($this_value);
        $this_oid = substr($this_oid, 30);
        list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode('.', $this_oid);
        $h_a = zeropad(dechex($a));
        $h_b = zeropad(dechex($b));
        $h_c = zeropad(dechex($c));
        $h_d = zeropad(dechex($d));
        $h_e = zeropad(dechex($e));
        $h_f = zeropad(dechex($f));
        $mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}";
        if ($dir == '1') {
            $dir = 'input';
        } elseif ($dir == '2') {
            $dir = 'output';
        }
        if ($mac && $dir) {
            $array[$ifIndex][$mac][$oid][$dir] = $this_value;
        }
    }
    //end foreach
    return $array;
}
开发者ID:Rosiak,项目名称:librenms,代码行数:30,代码来源:snmp.inc.php

示例9: preg_match

<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage discovery
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
// This could do with a rewrite.
echo " S5-CHASSIS-MIB ";
# Get major version number of running firmware
$fw_major_version = Null;
preg_match("/[0-9]\\.[0-9]/", $device['version'], $fw_major_version);
$fw_major_version = $fw_major_version[0];
# Temperature info only known to be present in firmware 6.1 or higher
if ($fw_major_version >= 6.1) {
    $temps = snmp_walk($device, "1.3.6.1.4.1.45.1.6.3.7.1.1.5.5", "-Osqn");
    $scale = 0.5;
    foreach (explode("\n", $temps) as $i => $t) {
        $t = explode(" ", $t);
        $oid = $t[0];
        $val = trim($t[1]);
        discover_sensor($valid['sensor'], 'temperature', $device, $oid, zeropad($i + 1), 'avaya-ers', "Unit " . ($i + 1) . " temperature", $scale, $val * $scale);
    }
}
// EOF
开发者ID:skive,项目名称:observium,代码行数:30,代码来源:s5-chassis-mib.inc.php

示例10: array

<?php

$mac_list = array();
// Disabled because we can do this better in poller now without performance hit
if ($device['os_group'] == "cisco" && FALSE) {
    echo "Cisco MAC Accounting : ";
    $datas = snmp_walk($device, "CISCO-IP-STAT-MIB::cipMacSwitchedBytes", "-OUqsX", "NS-ROOT-MIB");
    foreach (explode("\n", $datas) as $data) {
        list(, $ifIndex, $dir, $mac, ) = parse_oid2($data);
        list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $mac);
        $ah_a = zeropad($a_a);
        $ah_b = zeropad($a_b);
        $ah_c = zeropad($a_c);
        $ah_d = zeropad($a_d);
        $ah_e = zeropad($a_e);
        $ah_f = zeropad($a_f);
        $clean_mac = "{$ah_a}{$ah_b}{$ah_c}{$ah_d}{$ah_e}{$ah_f}";
        $mac_list[$ifIndex . '_' . $clean_mac] = array('ifIndex' => $ifIndex, 'mac' => $clean_mac);
    }
    foreach ($mac_list as $mac_entry) {
        $port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? LIMIT 1", array($device['device_id'], $mac_entry['ifIndex']));
        if ($port) {
            echo $port['ifDescr'] . ' (' . $mac_entry['ifIndex'] . ') -> ' . $mac_entry['mac'];
            if (dbFetchCell("SELECT COUNT(*) from `mac_accounting` WHERE `port_id` = ? AND `mac` = ?", array($port['port_id'], $mac_entry['mac']))) {
                echo ".";
            } else {
                $ma_id = dbInsert(array('port_id' => $port['port_id'], 'device_id' => $device['device_id'], 'mac' => $mac_entry['mac']), 'mac_accounting');
                dbInsert(array('ma_id' => $ma_id), 'mac_accounting-state');
                echo "+";
            }
        } else {
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:31,代码来源:mac-accounting.inc.php

示例11: char2hex

function char2hex($c)
{
    return zeropad(dechex(ord($c)), 2);
}
开发者ID:rbauduin,项目名称:amiusingmptcp,代码行数:4,代码来源:mptcp.inc.php

示例12: preg_match

<?php

if ($device['os'] == 'avaya-ers') {
    // Get major version number of running firmware
    $fw_major_version = null;
    preg_match('/[0-9]\\.[0-9]/', $device['version'], $fw_major_version);
    $fw_major_version = $fw_major_version[0];
    // Temperature info only known to be present in firmware 6.1 or higher
    if ($fw_major_version >= 6.1) {
        $temps = snmp_walk($device, '1.3.6.1.4.1.45.1.6.3.7.1.1.5.5', '-Osqn');
        foreach (explode("\n", $temps) as $i => $t) {
            $t = explode(' ', $t);
            $oid = $t[0];
            $val = $t[1];
            // Sensors are reported as 2 * value
            $val = trim($val) / 2;
            discover_sensor($valid['sensor'], 'temperature', $device, $oid, zeropad($i + 1), 'avaya-ers', 'Unit ' . ($i + 1) . ' temperature', '2', '1', null, null, null, null, $val);
        }
    }
}
开发者ID:szatam,项目名称:librenms,代码行数:20,代码来源:avaya-ers.inc.php

示例13: convert_color

function convert_color($color)
{
    $out = '';
    // We only accept color in #rgb, #rrggbb, and rgb(r,g,b) formats
    if (preg_match('/#(\\[0-9a-f])([0-9a-f])([0-9a-f])/i', $color, $matches)) {
        $out = '#' . $matches[1] . $matches[1] . $matches[2] . $matches[2] . $matches[3] . $matches[3];
    } else {
        if (preg_match('/#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i', $color, $matches)) {
            $out = '#' . $matches[1] . $matches[2] . $matches[3];
        } else {
            if (preg_match('/rgb\\((\\d+),\\s?(\\d+),\\s?(\\d+)\\)/', $color, $matches)) {
                $out = '#' . zeropad(dechex($matches[1]), 2) . zeropad(dechex($matches[2]), 2) . zeropad(dechex($matches[3]), 2);
            }
        }
    }
    return $out;
}
开发者ID:0hyeah,项目名称:yurivn,代码行数:17,代码来源:utils.php

示例14: snmp_walk

<?php

if ($device['os'] == 'avaya-ers') {
    // Processor information only know to work with 5500 and 5600 switches
    if (preg_match('/5[56][0-9][0-9]/', $device['sysDescr'])) {
        $procs = snmp_walk($device, '.1.3.6.1.4.1.45.1.6.3.8.1.1.6', '-Osqn');
        foreach (explode("\n", $procs) as $i => $t) {
            $t = explode(' ', $t);
            $oid = $t[0];
            $val = $t[1];
            discover_processor($valid['processor'], $device, $oid, zeropad($i + 1), 'avaya-ers', 'Unit ' . ($i + 1) . ' processor', '1', $val, $i, null);
        }
    }
}
开发者ID:samyscoub,项目名称:librenms,代码行数:14,代码来源:avaya-ers.inc.php

示例15: shell_exec

 $datas = shell_exec($config['snmpbulkwalk'] . " -m CISCO-IP-STAT-MIB -Oqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " cipMacSwitchedBytes");
 #echo("$datas\n");
 #echo("done\n");
 foreach (explode("\n", $datas) as $data) {
     list($oid) = explode(" ", $data);
     $oid = str_replace(".1.3.6.1.4.1.9.9.84.1.2.1.1.4.", "", $oid);
     list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $oid);
     $oid = "{$a_a}.{$a_b}.{$a_c}.{$a_d}.{$a_e}.{$a_f}";
     unset($interface);
     $interface = mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "' AND ifIndex = '" . $if . "'"));
     $ah_a = zeropad(dechex($a_a));
     $ah_b = zeropad(dechex($a_b));
     $ah_c = zeropad(dechex($a_c));
     $ah_d = zeropad(dechex($a_d));
     $ah_e = zeropad(dechex($a_e));
     $ah_f = zeropad(dechex($a_f));
     $mac = "{$ah_a}:{$ah_b}:{$ah_c}:{$ah_d}:{$ah_e}:{$ah_f}";
     $mac_cisco = "{$ah_a}{$ah_b}.{$ah_c}{$ah_d}.{$ah_e}{$ah_f}";
     $mac_cisco = $mac_table[$if][$mac]['ciscomac'];
     $clean_mac = $mac_table[$if][$mac]['cleanmac'];
     $ip = $mac_table[$if][$mac]['ip'];
     if ($ip && $interface) {
         $new_mac = str_replace(":", "", $mac);
         #echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip");
         if (mysql_result(mysql_query("SELECT COUNT(*) from mac_accounting WHERE interface_id = '" . $interface['interface_id'] . "' AND mac = '{$clean_mac}'"), 0)) {
             #$sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND `mac` = '$clean_mac'";
             #mysql_query($sql);
             #if(mysql_affected_rows()) { echo("      UPDATED!"); }
             #echo($sql);
             echo ".";
         } else {
开发者ID:kyrisu,项目名称:observernms,代码行数:31,代码来源:cisco-mac-accounting.inc.php


注:本文中的zeropad函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。