Home >>PHP String Functions >PHP str_repeat() Function
PHP str_repeat() function is used to get a new string by repeating a given input string fixed number of times. It takes a string and an integer as input parameters and returns a new string which is created by repeating the passed input string number of times defined by the integer passed in the argument to it.
Syntax:
str_repeat ( $string, $integer );
Parameter | Description |
---|---|
string | This is a required parameter. This parameter contains the string to be repeated. |
repeat | This is a required parameter. This parameter defines how many times the string will be repeated. |
Here is an example of str_repeat() function in PHP:
<html> <body> <?php echo str_repeat("PHP..",10); ?> </body> </html>
Here is an another example of str_repeat() function in PHP:
<html> <body> <?php echo str_repeat("I am the Best!! <br>",5); ?> </body> </html>