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


PHP str_repeat函数代码示例

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


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

示例1: start_el

 function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
 {
     $indent = $depth ? str_repeat("\t", $depth) : '';
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $classes[] = 'menu-item-' . $item->ID;
     $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth));
     /**
      * Change WP's default classes to match Foundation's required classes
      */
     $class_names = str_replace(array('menu-item-has-children'), array('has-submenu'), $class_names);
     // ==========================
     $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
     $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
     $id = $id ? ' id="' . esc_attr($id) . '"' : '';
     $output .= $indent . '<li' . $id . $class_names . '>';
     $atts = array();
     $atts['title'] = !empty($item->attr_title) ? $item->attr_title : '';
     $atts['target'] = !empty($item->target) ? $item->target : '';
     $atts['rel'] = !empty($item->xfn) ? $item->xfn : '';
     $atts['href'] = !empty($item->url) ? $item->url : '';
     $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
     $attributes = '';
     foreach ($atts as $attr => $value) {
         if (!empty($value)) {
             $value = 'href' === $attr ? esc_url($value) : esc_attr($value);
             $attributes .= ' ' . $attr . '="' . $value . '"';
         }
     }
     $item_output = $args->before;
     $item_output .= '<a' . $attributes . '>';
     $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
     $item_output .= '</a>';
     $item_output .= $args->after;
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
 }
开发者ID:andrewcroce,项目名称:TPL,代码行数:35,代码来源:offcanvas-walker.class.php

示例2: _str_pad

/**
 * utf8::str_pad
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
    if (utf8::is_ascii($str) and utf8::is_ascii($pad_str)) {
        return str_pad($str, $final_str_length, $pad_str, $pad_type);
    }
    $str_length = utf8::strlen($str);
    if ($final_str_length <= 0 or $final_str_length <= $str_length) {
        return $str;
    }
    $pad_str_length = utf8::strlen($pad_str);
    $pad_length = $final_str_length - $str_length;
    if ($pad_type == STR_PAD_RIGHT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return utf8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
    }
    if ($pad_type == STR_PAD_LEFT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return utf8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
    }
    if ($pad_type == STR_PAD_BOTH) {
        $pad_length /= 2;
        $pad_length_left = floor($pad_length);
        $pad_length_right = ceil($pad_length);
        $repeat_left = ceil($pad_length_left / $pad_str_length);
        $repeat_right = ceil($pad_length_right / $pad_str_length);
        $pad_left = utf8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
        $pad_right = utf8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_left);
        return $pad_left . $str . $pad_right;
    }
    trigger_error('utf8::str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR);
}
开发者ID:Toushi,项目名称:flow,代码行数:40,代码来源:str_pad.php

示例3: execute

 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $ids = $args->getArg('id');
     if (!$ids) {
         throw new PhutilArgumentUsageException(pht("Use the '%s' flag to specify one or more SMS messages to show.", '--id'));
     }
     $messages = id(new PhabricatorSMS())->loadAllWhere('id IN (%Ld)', $ids);
     if ($ids) {
         $ids = array_fuse($ids);
         $missing = array_diff_key($ids, $messages);
         if ($missing) {
             throw new PhutilArgumentUsageException(pht('Some specified SMS messages do not exist: %s', implode(', ', array_keys($missing))));
         }
     }
     $last_key = last_key($messages);
     foreach ($messages as $message_key => $message) {
         $info = array();
         $info[] = pht('PROPERTIES');
         $info[] = pht('ID: %d', $message->getID());
         $info[] = pht('Status: %s', $message->getSendStatus());
         $info[] = pht('To: %s', $message->getToNumber());
         $info[] = pht('From: %s', $message->getFromNumber());
         $info[] = null;
         $info[] = pht('BODY');
         $info[] = $message->getBody();
         $info[] = null;
         $console->writeOut('%s', implode("\n", $info));
         if ($message_key != $last_key) {
             $console->writeOut("\n%s\n\n", str_repeat('-', 80));
         }
     }
 }
开发者ID:pugong,项目名称:phabricator,代码行数:33,代码来源:PhabricatorSMSManagementShowOutboundWorkflow.php

示例4: testTooLargeMegaBytes

 public function testTooLargeMegaBytes()
 {
     fwrite($this->file, str_repeat('0', 1400000));
     $constraint = new File(array('maxSize' => '1M', 'maxSizeMessage' => 'myMessage'));
     $this->context->expects($this->once())->method('addViolation')->with('myMessage', array('{{ limit }}' => '1 MB', '{{ size }}' => '1.4 MB', '{{ file }}' => $this->path));
     $this->validator->validate($this->getFile($this->path), $constraint);
 }
开发者ID:nashadalam,项目名称:symfony,代码行数:7,代码来源:FileValidatorTest.php

示例5: hikashopSubscriptionType

 function hikashopSubscriptionType()
 {
     if (!HIKASHOP_PHP5) {
         $acl =& JFactory::getACL();
     } else {
         $acl = JFactory::getACL();
     }
     if (!HIKASHOP_J16) {
         $this->groups = $acl->get_group_children_tree(null, 'USERS', false);
     } else {
         $db = JFactory::getDBO();
         $db->setQuery('SELECT a.*, a.title as text, a.id as value  FROM #__usergroups AS a ORDER BY a.lft ASC');
         $this->groups = $db->loadObjectList('id');
         foreach ($this->groups as $id => $group) {
             if (isset($this->groups[$group->parent_id])) {
                 $this->groups[$id]->level = intval(@$this->groups[$group->parent_id]->level) + 1;
                 $this->groups[$id]->text = str_repeat('- - ', $this->groups[$id]->level) . $this->groups[$id]->text;
             }
         }
     }
     $this->choice = array();
     $this->choice[] = JHTML::_('select.option', 'none', JText::_('HIKA_NONE'));
     $this->choice[] = JHTML::_('select.option', 'special', JText::_('HIKA_CUSTOM'));
     $js = "function updateSubscription(map){\r\n\t\t\tchoice = document.adminForm['choice_'+map];\r\n\t\t\tchoiceValue = 'special';\r\n\t\t\tfor (var i=0; i < choice.length; i++){\r\n\t\t\t\tif (choice[i].checked){\r\n\t\t\t\t\tchoiceValue = choice[i].value;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\thiddenVar = document.getElementById('hidden_'+map);\r\n\t\t\tif(choiceValue != 'special'){\r\n\t\t\t\thiddenVar.value = choiceValue;\r\n\t\t\t\tif(hiddenVar.value == 'none') hiddenVar.value = '';\r\n\t\t\t\tdocument.getElementById('div_'+map).style.display = 'none';\r\n\t\t\t}else{\r\n\t\t\t\tdocument.getElementById('div_'+map).style.display = '';\r\n\t\t\t\tspecialVar = eval('document.adminForm.special_'+map);\r\n\t\t\t\tfinalValue = '';\r\n\t\t\t\tfor (var i=0; i < specialVar.length; i++){\r\n\t\t\t\t\tif (specialVar[i].checked){\r\n\t\t\t\t\t\tfinalValue += specialVar[i].value;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\thiddenVar.value = finalValue;\r\n\t\t\t}\r\n\t\t}";
     if (!HIKASHOP_PHP5) {
         $doc =& JFactory::getDocument();
     } else {
         $doc = JFactory::getDocument();
     }
     $doc->addScriptDeclaration($js);
 }
开发者ID:q0821,项目名称:esportshop,代码行数:31,代码来源:subscription.php

示例6: tearDownAfterClass

 public static function tearDownAfterClass()
 {
     if (!self::$timing) {
         echo "\n";
         return;
     }
     $class = get_called_class();
     echo "Timing results : {$class}\n";
     $s = sprintf("%40s %6s %9s %9s %4s\n", 'name', 'count', 'total', 'avg', '% best');
     echo str_repeat('=', strlen($s)) . "\n";
     echo $s;
     echo str_repeat('-', strlen($s)) . "\n";
     array_walk(self::$timing, function (&$value, $key) {
         $value['avg'] = round($value['total'] / $value['count'] * 1000000, 3);
     });
     usort(self::$timing, function ($a, $b) {
         $at = $a['avg'];
         $bt = $b['avg'];
         return $at === $bt ? 0 : ($at < $bt ? -1 : 1);
     });
     $best = self::$timing[0]['avg'];
     foreach (self::$timing as $timing) {
         printf("%40s %6d %7.3fms %7.3fus %4.1f%%\n", $timing['name'], $timing['count'], round($timing['total'] * 1000, 3), $timing['avg'], round($timing['avg'] / $best * 100, 3));
     }
     echo str_repeat('-', strlen($s)) . "\n\n";
     printf("\nTiming compensated for avg overhead for: timeIt of %.3fus and startTimer/endTimer of %.3fus per invocation\n\n", self::$timeItOverhead * 1000000, self::$startEndOverhead * 1000000);
     parent::tearDownAfterClass();
 }
开发者ID:mean-cj,项目名称:laravel-translation-manager,代码行数:28,代码来源:TranslationManagerTestCase.php

示例7: ss_hide_mail

 function ss_hide_mail($email)
 {
     $mail_segments = explode("@", $email);
     $half = (int) strlen($mail_segments[0]) / 2;
     $mail_segments[0] = str_repeat("*", $half) . substr($mail_segments[0], $half);
     return implode("@", $mail_segments);
 }
开发者ID:seriusokhatsky,项目名称:envato-api,代码行数:7,代码来源:envato-api-functions.php

示例8: getDirectory

function getDirectory($path = '.', $level = 0)
{
    $ignore = array('cgi-bin', '.', '..');
    // Directories to ignore when listing output. Many hosts
    // will deny PHP access to the cgi-bin.
    $dh = @opendir($path);
    // Open the directory to the handle $dh
    while (false !== ($file = readdir($dh))) {
        // Loop through the directory
        if (!in_array($file, $ignore)) {
            // Check that this file is not to be ignored
            str_repeat(' ', $level * 4);
            // Just to add spacing to the list, to better
            // show the directory tree.
            if (is_dir("{$path}/{$file}")) {
                // Its a directory, so we need to keep reading down...
                echo "{$path}/{$file};";
                getDirectory("{$path}/{$file}", $level + 1);
                // Re-call this same function but on a new directory.
                // this is what makes function recursive.
            } else {
                echo "{$path}/{$file};";
                // Just print out the filename
            }
        }
    }
    closedir($dh);
    // Close the directory handle
}
开发者ID:rogermelich,项目名称:consultesLdap,代码行数:29,代码来源:uploadPhotos.php

示例9: createRow

 protected function createRow($items, $aData = array(), $level = 1)
 {
     if ($items->count()) {
         foreach ($items as $itm) {
             $getter = 'get' . $this->getValueField();
             $aResultTmp = array('Value' => call_user_func(array($itm, $getter)), 'Name' => $this->getTextFormat());
             $aRs = array();
             if (preg_match_all("/:(.*):/iU", $aResultTmp['Name'], $aRs)) {
                 foreach ($aRs[1] as $k => $val) {
                     $value = $itm;
                     if (strpos($val, "-") !== false) {
                         $xVal = explode("-", $val);
                         foreach ($xVal as $_val) {
                             $sGetter = 'get' . $_val;
                             $value = call_user_func(array($value, $sGetter));
                         }
                     } else {
                         $sGetter = 'get' . $val;
                         $value = call_user_func(array($value, $sGetter));
                     }
                     $aResultTmp['Name'] = str_replace($aRs[0][$k], $value, $aResultTmp['Name']);
                 }
             }
             if ($this->getIsTree() && $level > 1) {
                 $aResultTmp['Name'] = str_repeat(" |-- ", $level - 1) . $aResultTmp['Name'];
             }
             $aData[] = $aResultTmp;
             if ($itm->hasChilds()) {
                 $aData = $this->createRow($itm->getChilds(), $aData, $level + 1);
             }
         }
     }
     return $aData;
 }
开发者ID:ruxon,项目名称:module-ruxon,代码行数:34,代码来源:RuxonFormViewListColumn.class.php

示例10: replace

 /**
  * 替换屏蔽字
  */
 public function replace()
 {
     $content = trim(urldecode($this->input['banword']));
     $symbol = trim(urldecode($this->input['symbol']));
     if (empty($content)) {
         $this->errorOutput(OBJECT_NULL);
     }
     $data = $this->banword($content);
     if ($data) {
         $replace = array();
         $find = array();
         foreach ($data as $v) {
             if (!empty($symbol) && $symbol != '*') {
                 $replace[] = $symbol;
             } else {
                 if (!empty($v['banwd'])) {
                     $replace[] = $v['banwd'];
                 } else {
                     $replace[] = str_repeat('*', mb_strlen($v['banname'], 'utf-8'));
                 }
             }
             $find[] = $v['banname'];
         }
         $content = str_replace($find, $replace, $content);
     }
     $this->addItem($content);
     $this->output();
 }
开发者ID:h3len,项目名称:Project,代码行数:31,代码来源:banword.php

示例11: start_el

 /**
  * Create the markup to start an element.
  *
  * @see Walker::start_el() for description of parameters.
  *
  * @param string $output Passed by reference. Used to append additional
  *        content.
  * @param object $item Menu item data object.
  * @param int $depth Depth of menu item. Used for padding.
  * @param object $args See {@Walker::start_el()}.
  * @param int $id See {@Walker::start_el()}.
  */
 public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
 {
     global $_nav_menu_placeholder;
     $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? intval($_nav_menu_placeholder) - 1 : -1;
     $possible_object_id = isset($item->post_type) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
     $possible_db_id = !empty($item->ID) && 0 < $possible_object_id ? (int) $item->ID : 0;
     $indent = $depth ? str_repeat("\t", $depth) : '';
     $output .= $indent . '<li>';
     $output .= '<label class="menu-item-title">';
     $output .= '<input type="checkbox" class="menu-item-checkbox';
     if (property_exists($item, 'label')) {
         $title = $item->label;
     }
     $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="' . esc_attr($item->object_id) . '" /> ';
     $output .= isset($title) ? esc_html($title) : esc_html($item->title);
     $output .= '</label>';
     if (empty($item->url)) {
         $item->url = $item->guid;
     }
     if (!in_array(array('umnm-menu', 'umnm-' . $item->post_excerpt . '-nav'), $item->classes)) {
         $item->classes[] = 'umnm-menu';
         $item->classes[] = 'umnm-' . $item->post_excerpt . '-nav';
     }
     // Menu item hidden fields
     $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
     $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="' . esc_attr($item->object) . '" />';
     $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="' . esc_attr($item->menu_item_parent) . '" />';
     $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="custom" />';
     $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="' . esc_attr($item->title) . '" />';
     $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="' . esc_attr($item->url) . '" />';
     $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="' . esc_attr($item->target) . '" />';
     $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="' . esc_attr($item->attr_title) . '" />';
     $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="' . esc_attr(implode(' ', $item->classes)) . '" />';
     $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="' . esc_attr($item->xfn) . '" />';
 }
开发者ID:wpdelighter,项目名称:ultimate-member-navigation-menu,代码行数:47,代码来源:class-umnm-walker-nav-menu-checklist.php

示例12: profileOut

 function profileOut($functionname)
 {
     global $wgDebugFunctionEntry;
     if ($wgDebugFunctionEntry) {
         $this->debug(str_repeat(' ', count($this->mWorkStack) - 1) . 'Exiting ' . $functionname . "\n");
     }
     list($ofname, , $ortime, $octime) = array_pop($this->mWorkStack);
     if (!$ofname) {
         $this->debug("Profiling error: {$functionname}\n");
     } else {
         if ($functionname == 'close') {
             $message = "Profile section ended by close(): {$ofname}";
             $functionname = $ofname;
             $this->debug("{$message}\n");
             $this->mCollated[$message] = $this->errorEntry;
         } elseif ($ofname != $functionname) {
             $message = "Profiling error: in({$ofname}), out({$functionname})";
             $this->debug("{$message}\n");
             $this->mCollated[$message] = $this->errorEntry;
         }
         $entry =& $this->mCollated[$functionname];
         $elapsedcpu = $this->getTime('cpu') - $octime;
         $elapsedreal = $this->getTime() - $ortime;
         if (!is_array($entry)) {
             $entry = $this->zeroEntry;
             $this->mCollated[$functionname] =& $entry;
         }
         $entry['cpu'] += $elapsedcpu;
         $entry['cpu_sq'] += $elapsedcpu * $elapsedcpu;
         $entry['real'] += $elapsedreal;
         $entry['real_sq'] += $elapsedreal * $elapsedreal;
         $entry['count']++;
     }
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:34,代码来源:ProfilerSimple.php

示例13: registerFatalHandler

 public function registerFatalHandler($level = null, $reservedMemorySize = 20)
 {
     register_shutdown_function(array($this, 'handleFatalError'));
     $this->reservedMemory = str_repeat(' ', 1024 * $reservedMemorySize);
     $this->fatalLevel = $level;
     $this->hasFatalErrorHandler = true;
 }
开发者ID:acrobat,项目名称:monolog,代码行数:7,代码来源:ErrorHandler.php

示例14: writePadding

 private function writePadding($data)
 {
     $padding = strlen($data) % 4;
     if ($padding) {
         return str_repeat("ª", 4 - $padding);
     }
 }
开发者ID:nakashu,项目名称:symfony,代码行数:7,代码来源:IcuResFileDumper.php

示例15: start_el

 /**
  * start_el function.
  * 
  * @access public
  * @param mixed &$output
  * @param mixed $item
  * @param int $depth (default: 0)
  * @param array $args (default: array())
  * @param int $id (default: 0)
  * @return void
  */
 function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
 {
     $indent = $depth ? str_repeat("\t", $depth) : '';
     $li_attributes = '';
     $class_names = $value = '';
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $classes[] = $args->has_children ? 'dropdown' : '';
     $classes[] = $item->current || $item->current_item_ancestor ? 'active' : '';
     $classes[] = 'menu-item-' . $item->ID;
     $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
     $class_names = ' class="' . esc_attr($class_names) . '"';
     $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args);
     $id = strlen($id) ? ' id="' . esc_attr($id) . '"' : '';
     $output .= $indent . '<li' . $id . $value . $class_names . $li_attributes . '>';
     $attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
     $attributes .= !empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
     $attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
     $attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
     $attributes .= $args->has_children ? ' class="dropdown-toggle" data-toggle="dropdown"' : '';
     $item_output = $args->before;
     $item_output .= '<a' . $attributes . '>';
     $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
     $item_output .= $args->has_children ? ' <b class="caret"></b></a>' : '</a>';
     $item_output .= $args->after;
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
 }
开发者ID:quinntron,项目名称:greendot,代码行数:37,代码来源:class-Upbootwp_Walker_Nav_Menu.php


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