How to repeat a string several times in php

青灯夜游
Release: 2023-03-15 09:52:01
Original
3763 people have browsed it

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.

How to repeat a string several times in php

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)
Copy after login

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);
?>
Copy after login

How to repeat a string several times in php

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!