PHP str_repeat() Function

Definition

The str_repeat() function repeats a string a specified number of times.

Syntax

PHP str_repeat() Function has the following syntax.

str_repeat(string,repeat)

Parameter

ParameterIs RequiredDescription
string Required.String to repeat
repeat Required. Number of times to repeat. Must be greater or equal to 0

Return

PHP str_repeat() function returns the repeated string.

Example

Repeat the string "java2s.com" 3 times:


<?php
echo str_repeat("java2s.com",3);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions