ホームページ >バックエンド開発 >PHPチュートリアル >PHP 関数が文字列を array_PHP チュートリアルに爆発的に変換する方法を分析する
学習中です1. PHP関数explodeの形式は次のとおりです:
arrayexplode(string separator, string string,[int limit]);
2. パラメータ内の区切り文字は、セパレータです。文字列は分割される文字列です。limit は返される配列内の要素の最大数です。
PHP関数explodeの具体的な使用例:
<ol class="dp-xml"> <li class="alt"> <span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN> $</SPAN><SPAN class=attribute><FONT color=#ff0000>DOCUMENT_ROOT</FONT></SPAN><SPAN> = $_SERVER['DOCUMENT_ROOT']; </SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>html</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>head</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>title</SPAN><SPAN class=tag>></span></font></strong><span>Test Explode</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>title</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>head</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>body</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN> $</SPAN><SPAN class=attribute><FONT color=#ff0000>peoples</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>file</FONT></SPAN><SPAN>($DOCUMENT_ROOT.'/test/03/people.txt'); </SPAN></SPAN><LI class=alt><SPAN> $</SPAN><SPAN class=attribute><FONT color=#ff0000>count</FONT></SPAN><SPAN class=attribute-value><FONT color=#0000ff>count</FONT></SPAN><SPAN> = count($peoples); </SPAN></SPAN><LI class=""><SPAN> if ($</SPAN><SPAN class=attribute><FONT color=#ff0000>count</FONT></SPAN><SPAN> == 0) { </SPAN></SPAN><LI class=alt><SPAN> echo 'NO peoples pending. Please try again later.'; </SPAN><LI class=""><SPAN> } </SPAN><LI class=alt><SPAN> for ($</SPAN><SPAN class=attribute><FONT color=#ff0000>i</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>0</FONT></SPAN><SPAN>; $i </SPAN><SPAN class=tag><STRONG><FONT color=#006699><</FONT></STRONG></SPAN><SPAN> $count; $i++) { </SPAN></SPAN><LI class=""><SPAN> $</SPAN><SPAN class=attribute><FONT color=#ff0000>line</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>explode</FONT></SPAN><SPAN>("t", $peoples[$i]); </SPAN></SPAN><LI class=alt><SPAN> echo '</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>font</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>color</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>red</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>'.$line[0].'</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>font</SPAN><SPAN class=tag>></span></font></strong><span>'; </span> </li> <li class=""> <span> echo '</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>font</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>color</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>blue</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>'.$line[1].'</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>font</SPAN><SPAN class=tag>></span></font></strong><span>'; </span> </li> <li class="alt"> <span> echo '</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>font</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>color</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>green</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>'.$line[2].'</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>font</SPAN><SPAN class=tag>></span></font></strong><span>'; </span> </li> <li class=""> <span> echo '</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=tag><STRONG><FONT color=#006699>/></span></font></strong><span>'; </span> </li> <li class="alt"><span> } </span></li> <li class=""> <span> </span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>body</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>html</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> </ol>
希望学習愛好家の大多数は、この記事で紹介する PHP 関数エクスプロードの使用例を通じて、PHP 関数エクスプロードの使い方を基本的に理解することができます。