PHP之string之str_repeat()函数使用

发布时间:2019-08-07 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了PHP之string之str_repeat()函数使用脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

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()函数使用全部内容,希望文章能够帮你解决PHP之string之str_repeat()函数使用所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。