function.str-split.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 160 行

HTML
160
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Convert a string to an array</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.str-shuffle.html">str_shuffle</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.str-word-count.html">str_word_count</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.str-split" class="refentry"> <div class="refnamediv">  <h1 class="refname">str_split</h1>  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">str_split</span> &mdash; <span class="dc-title">Convert a string to an array</span></p> </div>  <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">array</span> <span class="methodname"><b><b>str_split</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$string</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$split_length</tt></span>  ] )</div>  <p class="para rdfs-comment">   Converts a string to an array.   </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">string</tt></i></span>     <dd>      <p class="para">       The input string.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">split_length</tt></i></span>     <dd>      <p class="para">       Maximum length of the chunk.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   If the optional <i><tt class="parameter">split_length</tt></i> parameter is   specified, the returned array will be broken down into chunks with each   being <i><tt class="parameter">split_length</tt></i> in length, otherwise each chunk   will be one character in length.  </p>  <p class="para">   <b><tt>FALSE</tt></b> is returned if <i><tt class="parameter">split_length</tt></i> is less than 1.   If the <i><tt class="parameter">split_length</tt></i> length exceeds the length of   <i><tt class="parameter">string</tt></i>, the entire string is returned as the first   (and only) array element.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 Example uses of <b>str_split()</b></b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;Friend"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$arr1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_split</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$arr2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_split</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>    <div class="example-contents"><p>The above example will output:</p></div>    <div class="example-contents"><pre><div class="cdata"><pre>Array(    [0] =&gt; H    [1] =&gt; e    [2] =&gt; l    [3] =&gt; l    [4] =&gt; o    [5] =&gt;    [6] =&gt; F    [7] =&gt; r    [8] =&gt; i    [9] =&gt; e    [10] =&gt; n    [11] =&gt; d)Array(    [0] =&gt; Hel    [1] =&gt; lo    [2] =&gt; Fri    [3] =&gt; end)</pre></div>    </pre></div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.chunk-split.html" class="function" rel="rdfs-seeAlso">chunk_split()</a></li>    <li class="member"><a href="function.preg-split.html" class="function" rel="rdfs-seeAlso">preg_split()</a></li>    <li class="member"><a href="function.explode.html" class="function" rel="rdfs-seeAlso">explode()</a></li>    <li class="member"><a href="function.count-chars.html" class="function" rel="rdfs-seeAlso">count_chars()</a></li>    <li class="member"><a href="function.str-word-count.html" class="function" rel="rdfs-seeAlso">str_word_count()</a></li>    <li class="member"><a href="control-structures.for.html" class="link">for</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.str-shuffle.html">str_shuffle</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.str-word-count.html">str_word_count</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?