首页 > Web开发 > 详细

PHP之string之str_repeat()函数使用

时间:2018-03-06 22:43:51      阅读:219      评论:0      收藏:0      [点我收藏+]

str_repeat

  • (PHP 4, PHP 5, PHP 7)
  • str_repeat — Repeat a string
  • str_repeat — 重复一个字符串

Description

string str_repeat ( string $input , int $multiplier )
//Returns input repeated multiplier times.
//返回 input 重复 multiplier 次后的结果。

Parameters

input

  • The string to be repeated.
  • 待操作的字符串。

multiplier

  • Number of time the input string should be repeated.
  • input 被重复的次数。

  • multiplier has to be greater than or equal to 0. If the multiplier is set to 0, the function will return an empty string.
  • multiplier 必须大于等于 0。如果 multiplier 被设置为 0,函数返回空字符串。

Return Values

  • Returns the repeated string.
  • 返回重复后的字符串。

Examples

<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/2/20
 * Time: 下午11:50
 */
//------------------------------
echo str_repeat( "-", 30 ) . PHP_EOL;
//******************************
echo str_repeat( "*", 30 ) . PHP_EOL;

////////////////////////////////////////////////////////////////
$input      = 'bar';
$multiplier = 5;
$separator  = ',';
//bar,bar,bar,bar,bar
echo implode( $separator, array_fill( 0, $multiplier, $input ) ) . PHP_EOL;

//?,?,?
echo implode( ',', array_fill( 0, 3, '?' ) ) . PHP_EOL;


$my_head = str_repeat( "°~", 35 );
echo strlen( $my_head ) . PHP_EOL; // 105
echo mb_strlen( $my_head, 'UTF-8' ) . PHP_EOL; // 70
echo strlen( "°" ) . PHP_EOL;//2
echo strlen( "~" ) . PHP_EOL;//1
//°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~°~
echo $my_head . PHP_EOL;

See

All rights reserved

PHP之string之str_repeat()函数使用

原文:https://www.cnblogs.com/zhangrxiang/p/8519429.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!