LoginSignup
2
1

More than 5 years have passed since last update.

【PHP】文字列を繰り返し表示(_/_/_/_/_/_/...など)したい!→str_repeat()関数を使おう

Last updated at Posted at 2018-05-20

文字列を繰り返し表示するには?→str_repeat()関数

str_repeat()関数→指定した文字列を指定回数分繰り返した文字列を出力。

repeat_string.php

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>文字列を繰り返し表示する</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
</head>
<body>
<?php
echo "<p>「*」を15回繰り返す</p>";
// str_repeat(繰り返す文字列, 繰り返す回数)
echo "<p>".str_repeat('*', 15)."</p>";
// 出力結果→「***************」
echo "<p>「_/」を10回繰り返す</p>";
echo "<p>".str_repeat('_/', 10)."</p>";
// 出力結果→「_/_/_/_/_/_/_/_/_/_/」
 ?>
</body>
</html>

以上です。押忍!

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1