In PHP, you can use the str_repeat() function to repeat a string a specified number of times and return the repeated string; the syntax "str_repeat(string,repeat)", the parameter "repeat" specifies the string The number of times it will be repeated, its value must be greater than or equal to 0.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can use the str_repeat() function to repeat a string a specified number of times.
str_repeat() function repeats a string a specified number of times.
Syntax:
str_repeat(string,repeat)
The parameter string specifies the string to be repeated, and the parameter repeat specifies the number of times the string will be repeated. The str_repeat() function returns the result of string repeated repeat times.
Note: The value of parameter repeat must be greater than or equal to 0; if repeat is set to 0, the function will return an empty string.
Example:
<?php header("Content-type:text/html;charset=utf-8"); $str = "PHP是世界上最好的编程语言!<br />"; echo "重要的事情说三遍:<br />" . str_repeat($str, 3); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to repeat a string several times in php. For more information, please follow other related articles on the PHP Chinese website!