Analyze how the PHP function explode converts a string into an array_PHP tutorial

WBOY
Release: 2016-07-15 13:29:50
Original
865 people have browsed it

We are learning1. The format of PHP function explode is as follows:

array explode(string separator, string string,[int limit]);

2. The separator in the parameter is the separator, string is the string to be split, and limit is the maximum number of elements in the returned array.

Specific usage examples of PHP function 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>
Copy after login

I hope that through the usage examples of the PHP function explode introduced in this article, I hope that the majority of learning enthusiasts can Basically understand how to use the PHP function explode.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446337.htmlTechArticleWe are learning 1. The format of PHP function explode is as follows: array explode(string separator, string string,[int limit ]); 2. The separator in the parameter is the separator, string is the string to be split,...
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!