PHP 字符串函数

PHP str_repeat()函数用于将字符串重复指定的次数。

语法

str_repeat(string, repeat);

参数

参数描述必须/可选

string

指定要重复的字符串。必须
repeat指定重复次数。必须

返回值

返回重复指定次数后的字符串。

示例

介绍一些例子,了解PHP str_repeat()函数的使用方法。

示例1

<?php
echo str_repeat(".",13);
?>

输出:

..............

上面的例子中,将点.重复执行了13次。

示例2

<?php
echo str_repeat('-=',10);
?>

输出:

-=-=-=-=-=-=-=-=-=-=

上面的例子中,将-=重复执行了10次。

示例3

<?php
echo str_repeat('?',10);
?>

输出:

??????????