1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-26 00:32:15 +01:00
Files
archived-doc-ru/reference/strings/functions/str-split.xml
Mikhail Alferov bf94a1d6d7 Обновление перевода (#623)
Co-authored-by: Sergey Panteleev <sergey@php.net>
2023-12-29 14:01:59 +03:00

196 lines
5.5 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: e1621b408bdd443153611090847023aa39829bb0 Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.str-split" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>str_split</refname>
<refpurpose>Преобразовывает строку в массив</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>str_split</methodname>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>length</parameter><initializer>1</initializer></methodparam>
</methodsynopsis>
<para>
Преобразовывает строку в массив.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>string</parameter></term>
<listitem>
<para>
Входная строка.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>length</parameter></term>
<listitem>
<para>
Максимальная длина фрагмента.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Если указан необязательный параметр <parameter>length</parameter>,
возвращаемый массив будет разбит на фрагменты, каждый из которых будет иметь длину <parameter>length</parameter>,
за исключением последнего фрагмента, который может быть короче, если строка делится неравномерно.
По умолчанию параметр <parameter>length</parameter> равен <literal>1</literal>,
то есть размер каждого фрагмента будет один байт.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Если параметр <parameter>length</parameter> меньше <literal>1</literal>,
будет выброшена ошибка <classname>ValueError</classname>.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.2.0</entry>
<entry>
Если параметр <parameter>string</parameter> не задан, теперь возвращается пустой массив (&array;).
Ранее возвращался массив (&array;), содержащий одну пустую строку
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
Теперь если параметр <parameter>length</parameter> меньше <literal>1</literal>,
будет выброшена ошибка <classname>ValueError</classname>;
ранее, вместо этого выдавалась ошибка уровня <constant>E_WARNING</constant>,
а функция возвращала &false;.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования функции <function>str_split</function></title>
<programlisting role="php">
<![CDATA[
<?php
$str = "Hello Friend";
$arr1 = str_split($str);
$arr2 = str_split($str, 3);
print_r($arr1);
print_r($arr2);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
[5] =>
[6] => F
[7] => r
[8] => i
[9] => e
[10] => n
[11] => d
)
Array
(
[0] => Hel
[1] => lo
[2] => Fri
[3] => end
)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
Функция <function>str_split</function> производит разбивку по байтам,
а не по символам, в случае использования строк в многобайтных кодировках.
Используйте функцию <function>mb_str_split</function>, чтобы разбить строку на кодовые точки.
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>mb_str_split</function></member>
<member><function>chunk_split</function></member>
<member><function>preg_split</function></member>
<member><function>explode</function></member>
<member><function>count_chars</function></member>
<member><function>str_word_count</function></member>
<member><link linkend="control-structures.for">for</link></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->