文字列を置換する04
☆★データーでの確認★☆
文字列を繰り返す
str_repeat関数
- 同じ文字列を繰り返して、新たな文字列を生成する。
第1引数に「繰り返す文字列」第2引数に「繰り返す回数」を指定する。
【 書式 】
<?php // 「*」を20回繰り返す print str_repeat("*", 20) . "<br>"; // 改行の<br>タグを5回繰り返す print "PHP:Hypertext Preprocessor"; print str_repeat("<br>", 5) . "<br>"; print "PHP:Hypertext Preprocessor"; ?>
ソースコード
ソースコード【 HTML 】
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <meta name="description" content="文字列の処理"> <meta name="keywords" content="PHP,数値の処理"> <meta name="viewport" content="width=device-width"> <title>文字列の処理</title> <!-- IE対策 --> <!--[if ite IE 9]> <script src="http://html5shiv.googlecode.com/svn/ttunk/html5.js"></script> <![endif]--> <!--[if lte IE 9]> <script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script> <![endif]--> <style> article,aside,dialog,figure,footer,header, hgroup,menu,nav,section{ display: block;} </style> <link href="css/style.css" rel="stylesheet" type="text/css" media="all"> </head> <body> <div id="container"> <header> <h1>文字列を置換する</h1> </header> <div class="wrapper"> <section> <h1 class="title_top">文字列を繰り返す</h1> <p class="point"><span class="p">P</span>oint</p> <h2 class="title_main">str_repeat関数<span class="title_main_txt"> </span></h2> <dl> <dt>str_repeat関数</dt> <dd> <ul> <li>同じ文字列を繰り返して、新たな文字列を生成する。<br>第1引数に「繰り返す文字列」第2引数に「繰り返す回数」を指定する。</li> </dd> </dl> <h2 class="txt_web">< ブラウザでの表示 ></h2> <div class="txt_php"> <?php // 「*」を20回繰り返す print str_repeat("*", 20) . "<br>"; // 改行の<br>タグを5回繰り返す print "PHP:Hypertext Preprocessor"; print str_repeat("<br>", 5) . "<br>"; print "PHP:Hypertext Preprocessor"; ?> </div> </section> <!-- /.wrapper --> </div> <footer> <h1>PHPスクリプトの基本</h1> <small>Copyright© 2013 webry All Rights Reserved.</small> <small>参考資料:<span class="txt_small"><a href="d.hatena.ne.jp/webry/20130825/p2#php_sample_site" target="_blank">速攻&活用! Web開発者のためのPHPベストサンプル集</a></span> </footer> <!-- /#container --> </div> </body> </html>
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <meta name="description" content="文字列の処理"> <meta name="keywords" content="PHP,数値の処理"> <meta name="viewport" content="width=device-width"> <title>文字列の処理</title> <!-- IE対策 --> <!--[if ite IE 9]> <script src="http://html5shiv.googlecode.com/svn/ttunk/html5.js"></script> <![endif]--> <!--[if lte IE 9]> <script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script> <![endif]--> <style> article,aside,dialog,figure,footer,header, hgroup,menu,nav,section{ display: block;} </style> <link href="css/style.css" rel="stylesheet" type="text/css" media="all"> </head> <body> <div id="container"> <header> <h1>文字列を置換する</h1> </header> <div class="wrapper"> <section> <h1 class="title_top">文字列を繰り返す</h1> <p class="point"><span class="p">P</span>oint</p> <h2 class="title_main">str_repeat関数<span class="title_main_txt"> </span></h2> <dl> <dt>str_repeat関数</dt> <dd> <ul> <li>同じ文字列を繰り返して、新たな文字列を生成する。<br>第1引数に「繰り返す文字列」第2引数に「繰り返す回数」を指定する。</li> </dd> </dl> <h2 class="txt_web">< ブラウザでの表示 ></h2> <div class="txt_php"> <?php // 「*」を20回繰り返す print str_repeat("*", 20) . "<br>"; // 改行の<br>タグを5回繰り返す print "PHP:Hypertext Preprocessor"; print str_repeat("<br>", 5) . "<br>"; print "PHP:Hypertext Preprocessor"; ?> </div> </section> <!-- /.wrapper --> </div> <footer> <h1>PHPスクリプトの基本</h1> <small>Copyright© 2013 webry All Rights Reserved.</small> <small>参考資料:<span class="txt_small"><a href="d.hatena.ne.jp/webry/20130825/p2#php_sample_site" target="_blank">速攻&活用! Web開発者のためのPHPベストサンプル集</a></span> </footer> <!-- /#container --> </div> </body> </html>
ブラウザで表示【 FireFox 】
IEtester【 IE7 】
IEtester【 IE8 】
IEtester【 IE9 】
ブラウザで表示【 Chrome 】