1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-24 15:52:13 +01:00
Files
Mikhail Alferov c394cf8502 Update 45042fe to En (#1085)
* Update book.xml to en

* Update addcslashes.xml to en

* Update addslashes.xml to en

* Update sprintf.xml to en

* Update chr.xml to en

* Update chunk-split.xml to en

* Update echo.xml to en

* Update explode.xml to en

* Update fprintf.xml to en

* Update html-entity-decode.xml to en

* Update lcfirst.xml to en

* Update md5-file.xml to en

* Update number-format.xml to en

* Update ord.xml to en

* Update echo.xml

* Update print.xml to en

* Update setlocale.xml to en

* Update sha1-file.xml to en

* Update soundex.xml to en

* Update str-getcsv.xml to en

* Update str-pad.xml to en

* Update str-replace.xml to en

* Update stripos.xml to en

* Update stristr.xml to en

* Update strlen.xml to en

* Update strnatcmp.xml to en

* Update strpbrk.xml to en

* Update strpos.xml to en

* Update strrpos.xml to en

* Update strstr.xml to en

* Update strtok.xml toen

* Update strtr.xml to en

* Update substr-compare.xml to en

* Update substr-count.xml to en

* Update substr.xml to en

* Update ucfirst.xml to en

* Update ucwords.xml to en

* Update vfprintf.xml to en
2025-07-04 19:30:56 +03:00

266 lines
8.5 KiB
XML
Raw Permalink 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: 45042fef652f1b4e904e809fcbfcf31f6c60670b Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.explode" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>explode</refname>
<refpurpose>Разбивает строку разделителем</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>explode</methodname>
<methodparam><type>string</type><parameter>separator</parameter></methodparam>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>limit</parameter><initializer><constant>PHP_INT_MAX</constant></initializer></methodparam>
</methodsynopsis>
<para>
Функция возвращает массив строк, каждая из которых — подстрока,
которая образовалась за счёт разделения строки <parameter>string</parameter>
по границам, которые образовала строка-разделитель <parameter>separator</parameter>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>separator</parameter></term>
<listitem>
<para>
Разделитель.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>string</parameter></term>
<listitem>
<para>
Входная строка.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>limit</parameter></term>
<listitem>
<para>
Функция вернёт массив, который будет содержать максимум <parameter>limit</parameter> элементов,
при этом последний элемент будет содержать остаток строки <parameter>string</parameter>.
</para>
<para>
Функция вернёт все компоненты за вычетом
заданного в параметре <parameter>limit</parameter> количества элементов с конца,
если параметр <parameter>limit</parameter> отрицательный.
</para>
<para>
Функция расценит значение <parameter>limit</parameter> как 1, если параметр равен нулю.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<note>
<para>
До PHP 8.0 функция <function>implode</function> принимала параметры в любом порядке.
Функция <function>explode</function> никогда этого не поддерживала: убедитесь,
что разделитель <parameter>separator</parameter> идёт перед строкой <parameter>string</parameter>.
</para>
</note>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Функция возвращает массив (<type>array</type>) строк (<type>string</type>),
который она создаёт разделением строки <parameter>string</parameter>
по границам, которые образовал разделитель <parameter>separator</parameter>.
</para>
<para>
Функция <function>explode</function> выбрасывает исключение <classname>ValueError</classname>,
если разделитель <parameter>separator</parameter> — пустая строка "".
Функция возвращает пустой массив (<type>array</type>), если разделителя <parameter>separator</parameter>
нет в строке <parameter>string</parameter>
и задали отрицательное значение параметра <parameter>limit</parameter>,
иначе возвращает массив, который содержит строку <parameter>string</parameter>.
Функция добавит значения как пустые значения массива (<type>array</type>)
в первой или в последней позиции массива (<type>array</type>), который она возвращает,
если значения разделителя <parameter>separator</parameter> появляются
в начале или в конце строки <parameter>string</parameter>, соответственно.
</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.0.0</entry>
<entry>
Теперь функция <function>explode</function> выбрасывает исключение <classname>TypeError</classname>,
если разделитель <parameter>separator</parameter> — пустая строка <literal>""</literal>.
Раньше функция <function>explode</function> вместо исключения возвращала &false;.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования функции <function>explode</function></title>
<programlisting role="php">
<![CDATA[
<?php
// Пример 1
$pizza = "кусок1 кусок2 кусок3 кусок4 кусок5 кусок6";
$pieces = explode(" ", $pizza);
echo $pieces[0], PHP_EOL; // кусок1
echo $pieces[1], PHP_EOL; // кусок2
// Пример 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user, PHP_EOL; // foo
echo $pass, PHP_EOL; // *
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Пример значения, которое возвращает функция <function>explode</function></title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Строка, которая не содержит разделителя, будет
* просто возвращать массив с одним значением оригинальной строки.
*/
$input1 = "hello";
$input2 = "hello,there";
$input3 = ',';
var_dump( explode( ',', $input1 ) );
var_dump( explode( ',', $input2 ) );
var_dump( explode( ',', $input3 ) );
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(1)
(
[0] => string(5) "hello"
)
array(2)
(
[0] => string(5) "hello"
[1] => string(5) "there"
)
array(2)
(
[0] => string(0) ""
[1] => string(0) ""
)
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Примеры работы функции с параметром <parameter>limit</parameter></title>
<programlisting role="php">
<![CDATA[
<?php
$str = 'один|два|три|четыре';
// положительный лимит
print_r(explode('|', $str, 2));
// отрицательный лимит
print_r(explode('|', $str, -1));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[0] => один
[1] => два|три|четыре
)
Array
(
[0] => один
[1] => два
[2] => три
)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.bin-safe;
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>preg_split</function></member>
<member><function>str_split</function></member>
<member><function>mb_split</function></member>
<member><function>str_word_count</function></member>
<member><function>strtok</function></member>
<member><function>implode</function></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
-->