mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 15:12:23 +01:00
260 lines
6.9 KiB
XML
260 lines
6.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 45042fef652f1b4e904e809fcbfcf31f6c60670b Maintainer: leonardolara Status: ready --><!-- CREDITS: leonardolara -->
|
|
<refentry xml:id="function.explode" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>explode</refname>
|
|
<refpurpose>Divide uma string com base em outra string</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>
|
|
Retorna um array de strings, sendo que cada uma é uma sub-string da
|
|
<parameter>string</parameter>, formado pela separação dela nos
|
|
limites formados pela string informada em <parameter>separator</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>separator</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
A string que define o separador.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>string</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
A string de entrada.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>limit</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Se <parameter>limit</parameter> estiver definido e for positivo, o array retornado conterá
|
|
um máximo de <parameter>limit</parameter> elementos com o último
|
|
elemento contendo todo o restante da <parameter>string</parameter>.
|
|
</para>
|
|
<para>
|
|
Se <parameter>limit</parameter> for negativo, todos os componentes
|
|
exceto os (último - <parameter>limit</parameter>) são retornados.
|
|
</para>
|
|
<para>
|
|
Se <parameter>limit</parameter> for zero, é tratado como 1.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Antes do PHP 8.0, <function>implode</function> aceitava seus dois primeiros parâmetros em qualquer ordem.
|
|
A função <function>explode</function> nunca suportou isto: deve-se garantir que
|
|
o parâmetro <parameter>separator</parameter> vem antes do
|
|
parâmetro <parameter>string</parameter>.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna um <type>array</type> de <type>string</type>s
|
|
criado pela separação da <parameter>string</parameter> nos limites
|
|
formados pelo parâmetro <parameter>separator</parameter>.
|
|
</para>
|
|
<para>
|
|
Se <parameter>separator</parameter> for uma <type>string</type> vazia (""),
|
|
<function>explode</function> lança um <classname>ValueError</classname>.
|
|
Se <parameter>separator</parameter> contiver um valor não
|
|
contido em <parameter>string</parameter> e um valor negativo
|
|
for usado em <parameter>limit</parameter>, um <type>array</type> vazio será
|
|
retornado, caso contrário um <type>array</type> contendo
|
|
<parameter>string</parameter> será retornado. Se valores de <parameter>separator</parameter>
|
|
aparecerem no início ou no final da <parameter>string</parameter>, said values
|
|
elementos de <type>array</type> vazios serão adicionados na posição inicial ou
|
|
final do <type>array</type> retornado, respectivamente.
|
|
</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> agora lança um <classname>ValueError</classname>
|
|
quando <parameter>separator</parameter> é informado com uma string vazia
|
|
(<literal>""</literal>).
|
|
Anteriormente, <function>explode</function> retornava &false; nesse caso.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplos de <function>explode</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Exemplo 1
|
|
$pizza = "fatia1 fatia2 fatia3 fatia4 fatia5 fatia6";
|
|
$fatias = explode(" ", $pizza);
|
|
echo $fatias[0], PHP_EOL; // fatia1
|
|
echo $fatias[1], PHP_EOL; // fatia2
|
|
|
|
// Exemplo 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>Exemplo de retorno de <function>explode</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/*
|
|
Uma string que não contém o separador simplesmente
|
|
irá retornar um array de 1 elemento com a string original.
|
|
*/
|
|
$input1 = "olá";
|
|
$input2 = "olá,mundo";
|
|
$input3 = ',';
|
|
var_dump( explode( ',', $input1 ) );
|
|
var_dump( explode( ',', $input2 ) );
|
|
var_dump( explode( ',', $input3 ) );
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(1)
|
|
(
|
|
[0] => string(3) "olá"
|
|
)
|
|
array(2)
|
|
(
|
|
[0] => string(3) "olá"
|
|
[1] => string(5) "mundo"
|
|
)
|
|
array(2)
|
|
(
|
|
[0] => string(0) ""
|
|
[1] => string(0) ""
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Exemplos do parâmetro <parameter>limit</parameter></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$str = 'um|dois|três|quatro';
|
|
|
|
// limite positivo
|
|
print_r(explode('|', $str, 2));
|
|
|
|
// limite negativo
|
|
print_r(explode('|', $str, -1));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => um
|
|
[1] => dois|três|quatro
|
|
)
|
|
Array
|
|
(
|
|
[0] => um
|
|
[1] => dois
|
|
[2] => três
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
¬e.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
|
|
-->
|