PHP str_repeat() string function

The str_repeat() function in PHP

The str_repeat() function used to repeat a word for specified number of times.

str_repeat() function syntax

str_repeat(“repeat string”, number of time”);

PHP str_repeat() function example

echo "The string repeat = ".str_repeat( "Meera", 4 );

The output is:

The string repeat = MeeraMeeraMeeraMeera


PHP str_repeat string function example

<title>PHP str_repeat() Function</title>

<FORM method="POST" action="firstexample.php">

Name : <input type="text" name="name"> <br/>
Repeat :<input type="text" name="no"><br/>
<input type="submit" name="Submit1" value="String Repeat">


echo "The string repeat = ".str_repeat( $_POST["name"], $_POST["no"] );


The output screen of php string function example :

PHP str_repeat string function
PHP str_repeat string function

In above str_repeat function php example we have two textboxes first for input text value and other for integer value to repeat how many times repeated the text.

1 thought on “PHP str_repeat() string function

Leave a Reply

Your email address will not be published. Required fields are marked *