<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ru',
  ),
  'this' => 
  array (
    0 => 'function.str-split.php',
    1 => 'str_split',
    2 => 'Преобразовывает строку в массив',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'Функции для работы со строками',
  ),
  'prev' => 
  array (
    0 => 'function.str-shuffle.php',
    1 => 'str_shuffle',
  ),
  'next' => 
  array (
    0 => 'function.str-starts-with.php',
    1 => 'str_starts_with',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ru',
    'path' => 'reference/strings/functions/str-split.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.str-split" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_split</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">str_split</span> &mdash; <span class="dc-title">Преобразовывает строку в массив</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.str-split-description">
  <h3 class="title">Описание</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>str_split</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$length</code><span class="initializer"> = 1</span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Функция разбивает строку на элементы массива.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.str-split-parameters">
  <h3 class="title">Список параметров</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       Входная строка.
      </p>
     </dd>
    
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       Максимальная длина части.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.str-split-returnvalues">
  <h3 class="title">Возвращаемые значения</h3>
  <p class="para">
   Функция возвращает массив строк.
   Функция разобьёт строку на части заданной длины,
   если указали необязательный аргумент <code class="parameter">length</code>.
   Длина каждой части будет равна значению аргумента <code class="parameter">length</code>,
   за исключением последней части, длина которой будет меньше, если строка делится неравномерно.
   Значение параметра <code class="parameter">length</code> по умолчанию — <code class="literal">1</code> байт.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.str-split-errors">
  <h3 class="title">Ошибки</h3>
  <p class="para">
   Функция выбросит ошибку <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>,
   если значение аргумента <code class="parameter">length</code> окажется меньше <code class="literal">1</code>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.str-split-changelog">
  <h3 class="title">Список изменений</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версия</th>
      <th>Описание</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.2.0</td>
      <td>
       Функция теперь возвращает пустой массив (<span class="type"><a href="language.types.array.php" class="type array">array</a></span>), если параметр <code class="parameter">string</code> не указали;
       раньше возвращался массив (<span class="type"><a href="language.types.array.php" class="type array">array</a></span>), который содержал одну пустую строку.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Функция теперь выбросит ошибку <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>,
       если значение аргумента <code class="parameter">length</code> окажется меньше <code class="literal">1</code>;
       раньше вместо этого функция вызывала ошибку уровня <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>
       и возвращала <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.str-split-examples">
  <h3 class="title">Примеры</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Пример #1 Пример преобразования строки в массив функцией <span class="function"><strong>str_split()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">"Hello Friend"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$arr1 </span><span style="color: #007700">= </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 </span><span style="color: #007700">= </span><span style="color: #0000BB">str_split</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </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>
 Результат выполнения приведённого примера:
</p></div>

    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">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>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.str-split-notes">
  <h3 class="title">Примечания</h3>
  <blockquote class="note"><p><strong class="note">Замечание</strong>: 
   <p class="para">
    Функция <span class="function"><strong>str_split()</strong></span> разбивает строки
    в многобайтовых кодировках по байтам, а не по символам.
    На кодовые точки строку разбивает функция <span class="function"><a href="function.mb-str-split.php" class="function">mb_str_split()</a></span>.
    Для разбиения строки на кластеры графем вызывают функцию <span class="function"><a href="function.grapheme-str-split.php" class="function">grapheme_str_split()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.str-split-seealso">
  <h3 class="title">Смотрите также</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.mb-str-split.php" class="function" rel="rdfs-seeAlso">mb_str_split()</a> - Возвращает массив символов многобайтовой строки</span></li>
    <li><span class="function"><a href="function.grapheme-str-split.php" class="function" rel="rdfs-seeAlso">grapheme_str_split()</a> - Разбивает строку на массив графемных кластеров</span></li>
    <li><span class="function"><a href="function.chunk-split.php" class="function" rel="rdfs-seeAlso">chunk_split()</a> - Разбивает строку на фрагменты</span></li>
    <li><span class="function"><a href="function.preg-split.php" class="function" rel="rdfs-seeAlso">preg_split()</a> - Разбивает строку по регулярному выражению</span></li>
    <li><span class="function"><a href="function.explode.php" class="function" rel="rdfs-seeAlso">explode()</a> - Разбивает строку разделителем</span></li>
    <li><span class="function"><a href="function.count-chars.php" class="function" rel="rdfs-seeAlso">count_chars()</a> - Возвращает информацию о символах, которые входят в строку</span></li>
    <li><span class="function"><a href="function.str-word-count.php" class="function" rel="rdfs-seeAlso">str_word_count()</a> - Возвращает информацию о словах, которые входят в строку</span></li>
    <li><a href="control-structures.for.php" class="link">Цикл for</a></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>