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


PHP Toolbox::str_pad方法代码示例

本文整理汇总了PHP中Toolbox::str_pad方法的典型用法代码示例。如果您正苦于以下问题:PHP Toolbox::str_pad方法的具体用法?PHP Toolbox::str_pad怎么用?PHP Toolbox::str_pad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Toolbox的用法示例。


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

示例1: formatXML

 /**
  * Format XML, ie indent it for pretty printing
  *
  * @param $xml simplexml object
  * @return string
  **/
 static function formatXML($xml)
 {
     $string = str_replace("><", ">\n<", $xml->asXML());
     $token = strtok($string, "\n");
     $result = '';
     $pad = 0;
     $matches = array();
     $indent = 0;
     while ($token !== FALSE) {
         // 1. open and closing tags on same line - no change
         if (preg_match('/.+<\\/\\w[^>]*>$/', $token, $matches)) {
             $indent = 0;
             // 2. closing tag - outdent now
         } else {
             if (preg_match('/^<\\/\\w/', $token, $matches)) {
                 $pad = $pad - 3;
                 // 3. opening tag - don't pad this one, only subsequent tags
             } else {
                 if (preg_match('/^<\\w[^>]*[^\\/]>.*$/', $token, $matches)) {
                     $indent = 3;
                 } else {
                     $indent = 0;
                 }
             }
         }
         $line = Toolbox::str_pad($token, strlen($token) + $pad, '  ', STR_PAD_LEFT);
         $result .= $line . "\n";
         $token = strtok("\n");
         $pad += $indent;
         $indent = 0;
     }
     return $result;
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:39,代码来源:toolbox.class.php

示例2: displayProgressBar

 /**
  * Display a simple progress bar
  *
  * @param $width       Width    of the progress bar
  * @param $percent     Percent  of the progress bar
  * @param $options     array of possible options:
  *            - title : string title to display (default Progesssion)
  *            - simple : display a simple progress bar (no title / only percent)
  *            - forcepadding : boolean force str_pad to force refresh (default true)
  *
  * @return nothing
  **/
 static function displayProgressBar($width, $percent, $options = array())
 {
     global $CFG_GLPI;
     $param['title'] = __('Progress');
     $param['simple'] = false;
     $param['forcepadding'] = true;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $param[$key] = $val;
         }
     }
     $percentwidth = floor($percent * $width / 100);
     $output = "<div class='center'><table class='tab_cadre' width='" . ($width + 20) . "px'>";
     if (!$param['simple']) {
         $output .= "<tr><th class='center'>" . $param['title'] . "&nbsp;" . $percent . "%</th></tr>";
     }
     $output .= "<tr><td>\n                   <table class='tabcompact'><tr><td class='center' style='background:url(" . $CFG_GLPI["root_doc"] . "/pics/loader.png) repeat-x; padding: 0px;font-size: 10px;' width='" . $percentwidth . " px' height='12'>";
     if ($param['simple']) {
         $output .= $percent . "%";
     } else {
         $output .= '&nbsp;';
     }
     $output .= "</td></tr></table></td>";
     $output .= "</tr></table>";
     $output .= "</div>";
     if (!$param['forcepadding']) {
         echo $output;
     } else {
         echo Toolbox::str_pad($output, 4096);
         self::glpi_flush();
     }
 }
开发者ID:OlivierLM,项目名称:glpi,代码行数:44,代码来源:html.class.php

示例3: autoName

/**
 * Create a new name using a autoname field defined in a template
 *
 * @param $objectName      autoname template
 * @param $field           field to autoname
 * @param $isTemplate      true if create an object from a template
 * @param $itemtype        item type
 * @param $entities_id     limit generation to an entity (default -1)
 *
 * @return new auto string
**/
function autoName($objectName, $field, $isTemplate, $itemtype, $entities_id = -1)
{
    global $DB, $CFG_GLPI;
    $len = Toolbox::strlen($objectName);
    if ($isTemplate && $len > 8 && Toolbox::substr($objectName, 0, 4) === '&lt;' && Toolbox::substr($objectName, $len - 4, 4) === '&gt;') {
        $autoNum = Toolbox::substr($objectName, 4, $len - 8);
        $mask = '';
        if (preg_match("/\\#{1,10}/", $autoNum, $mask)) {
            $global = strpos($autoNum, '\\g') !== false && $itemtype != 'Infocom' ? 1 : 0;
            $autoNum = str_replace(array('\\y', '\\Y', '\\m', '\\d', '_', '%', '\\g'), array(date('y'), date('Y'), date('m'), date('d'), '\\_', '\\%', ''), $autoNum);
            $mask = $mask[0];
            $pos = strpos($autoNum, $mask) + 1;
            $len = Toolbox::strlen($mask);
            $like = str_replace('#', '_', $autoNum);
            if ($global == 1) {
                $query = "";
                $first = 1;
                $types = array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer');
                foreach ($types as $t) {
                    $table = getTableForItemType($t);
                    $query .= ($first ? "SELECT " : " UNION SELECT  ") . " {$field} AS code\n                         FROM `{$table}`\n                         WHERE `{$field}` LIKE '{$like}'\n                               AND `is_deleted` = '0'\n                               AND `is_template` = '0'";
                    if ($CFG_GLPI["use_autoname_by_entity"] && $entities_id >= 0) {
                        $query .= " AND `entities_id` = '{$entities_id}' ";
                    }
                    $first = 0;
                }
                $query = "SELECT CAST(SUBSTRING(code, {$pos}, {$len}) AS unsigned) AS no\n                      FROM ({$query}) AS codes";
            } else {
                $table = getTableForItemType($itemtype);
                $query = "SELECT CAST(SUBSTRING({$field}, {$pos}, {$len}) AS unsigned) AS no\n                      FROM `{$table}`\n                      WHERE `{$field}` LIKE '{$like}' ";
                if ($itemtype != 'Infocom') {
                    $query .= " AND `is_deleted` = '0'\n                           AND `is_template` = '0'";
                    if ($CFG_GLPI["use_autoname_by_entity"] && $entities_id >= 0) {
                        $query .= " AND `entities_id` = '{$entities_id}' ";
                    }
                }
            }
            $query = "SELECT MAX(Num.no) AS lastNo\n                   FROM (" . $query . ") AS Num";
            $resultNo = $DB->query($query);
            if ($DB->numrows($resultNo) > 0) {
                $data = $DB->fetch_assoc($resultNo);
                $newNo = $data['lastNo'] + 1;
            } else {
                $newNo = 0;
            }
            $objectName = str_replace(array($mask, '\\_', '\\%'), array(Toolbox::str_pad($newNo, $len, '0', STR_PAD_LEFT), '_', '%'), $autoNum);
        }
    }
    return $objectName;
}
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:61,代码来源:db.function.php


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