English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP str_repeat() Function Usage and Example

PHP String Character String Function Manual

The str_repeat() function is used to repeat a string a specified number of times.

Syntax

str_repeat ( string $string , int $repeat)

Definition and Usage

It is used to repeat the string (string) a specified (repeat) number of times.

Return Value

It returns the repeated string

Parameter

Serial NumberParameter and Description
1

string

It specifies the string to be repeated

2

repeat

It specifies the number of times the string is repeated

Online Example

Try the following example, repeat the string “w3codebox”Repeat5times and the string “-=”Repeat10times:

<?php
   //Repeat the string “oldtoolbag.com ”Repeat5times.
   echo str_repeat("oldtoolbag.com ",5);
   echo '<br>';
   //Repeat the string-Repeat10times.
   echo str_repeat("-=", 10);
?>
Test and See‹/›

Output Result

oldtoolbag.com oldtoolbag.com oldtoolbag.com oldtoolbag.com oldtoolbag.com 
-=-=-=-=-=-=-=-=-=-=

PHP String Character String Function Manual