Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 9138

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>preg_split</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Regular Expression Functions (Perl-Compatible)"
HREF="ref.pcre.html"><LINK
REL="PREVIOUS"
TITLE="preg_replace"
HREF="function.preg-replace.html"><LINK
REL="NEXT"
TITLE="PDF Funções"
HREF="ref.pdf.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual do PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.preg-replace.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="ref.pdf.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.preg-split"
></A
>preg_split</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN167500"
></A
><P
>    (PHP 3 &#62;= 3.0.9, PHP 4, PHP 5)</P
>preg_split&nbsp;--&nbsp;Split string by a regular expression</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167503"
></A
><H2
>Descrição</H2
>array <B
CLASS="methodname"
>preg_split</B
> ( string pattern, string subject [, int limit [, int flags]] )<BR
></BR
><P
>&#13;   Split the given string by a regular expression.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167521"
></A
><H2
>Parâmetros</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>pattern</CODE
></DT
><DD
><P
>&#13;       The pattern to search for, as a string.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>subject</CODE
></DT
><DD
><P
>&#13;       The input string.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>limit</CODE
></DT
><DD
><P
>&#13;       If specified, then only substrings up to <CODE
CLASS="parameter"
>limit</CODE
>
       are returned, and if <CODE
CLASS="parameter"
>limit</CODE
> is -1, it actually
       means "no limit", which is useful for specifying the
       <CODE
CLASS="parameter"
>flags</CODE
>.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>flags</CODE
></DT
><DD
><P
>&#13;       <CODE
CLASS="parameter"
>flags</CODE
> can be any combination of the following
       flags (combined with bitwise | operator):
       <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="constant"
><B
>PREG_SPLIT_NO_EMPTY</B
></TT
></DT
><DD
><P
>&#13;          If this flag is set, only non-empty pieces will be returned by
          <B
CLASS="function"
>preg_split()</B
>.
          </P
></DD
><DT
><TT
CLASS="constant"
><B
>PREG_SPLIT_DELIM_CAPTURE</B
></TT
></DT
><DD
><P
>&#13;          If this flag is set, parenthesized expression in the delimiter pattern
          will be captured and returned as well.
          </P
></DD
><DT
><TT
CLASS="constant"
><B
>PREG_SPLIT_OFFSET_CAPTURE</B
></TT
></DT
><DD
><P
>&#13;           If this flag is set, for every occurring match the appendant string
           offset will also be returned. Note that this changes the return
           value in an array where every element is an array consisting of the
           matched string at offset <TT
CLASS="literal"
>0</TT
> and its string offset
           into <CODE
CLASS="parameter"
>subject</CODE
> at offset <TT
CLASS="literal"
>1</TT
>.
          </P
></DD
></DL
></DIV
>
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167569"
></A
><H2
>Valores de retornado</H2
><P
>&#13;   Returns an array containing substrings of <CODE
CLASS="parameter"
>subject</CODE
>
   split along boundaries matched by <CODE
CLASS="parameter"
>pattern</CODE
>.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167574"
></A
><H2
>Histórico</H2
><P
>&#13;   <DIV
CLASS="informaltable"
><P
></P
><A
NAME="AEN167577"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Versão</TH
><TH
>Descrição</TH
></TR
></THEAD
><TBODY
><TR
><TD
>4.3.0</TD
><TD
>&#13;        The <TT
CLASS="constant"
><B
>PREG_SPLIT_OFFSET_CAPTURE</B
></TT
> was added
       </TD
></TR
><TR
><TD
>4.0.5</TD
><TD
>&#13;        The <TT
CLASS="constant"
><B
>PREG_SPLIT_DELIM_CAPTURE</B
></TT
> was added
       </TD
></TR
><TR
><TD
>4.0.0</TD
><TD
>&#13;        The <CODE
CLASS="parameter"
>flags</CODE
> parameter was added
       </TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167596"
></A
><H2
>Exemplos</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN167599"
></A
><P
><B
>Exemplo 1. <B
CLASS="function"
>preg_split()</B
> example : Get the parts of a search string</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">// split the phrase by any number of commas or space characters,<br />// which include " ", \r, \t, \n and \f<br /></font><font color="#0000BB">$keywords </font><font color="#007700">= </font><font color="#0000BB">preg_split</font><font color="#007700">(</font><font color="#DD0000">"/[\s,]+/"</font><font color="#007700">, </font><font color="#DD0000">"hypertext language, programming"</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN167604"
></A
><P
><B
>Exemplo 2. Splitting a string into component characters</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$str </font><font color="#007700">= </font><font color="#DD0000">'string'</font><font color="#007700">;<br /></font><font color="#0000BB">$chars </font><font color="#007700">= </font><font color="#0000BB">preg_split</font><font color="#007700">(</font><font color="#DD0000">'//'</font><font color="#007700">, </font><font color="#0000BB">$str</font><font color="#007700">, -</font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#0000BB">PREG_SPLIT_NO_EMPTY</font><font color="#007700">);<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$chars</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN167608"
></A
><P
><B
>Exemplo 3. Splitting a string into matches and their offsets</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$str </font><font color="#007700">= </font><font color="#DD0000">'hypertext language programming'</font><font color="#007700">;<br /></font><font color="#0000BB">$chars </font><font color="#007700">= </font><font color="#0000BB">preg_split</font><font color="#007700">(</font><font color="#DD0000">'/ /'</font><font color="#007700">, </font><font color="#0000BB">$str</font><font color="#007700">, -</font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#0000BB">PREG_SPLIT_OFFSET_CAPTURE</font><font color="#007700">);<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$chars</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>O exemplo acima irá imprimir:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Array
(
    [0] =&#62; Array
        (
            [0] =&#62; hypertext
            [1] =&#62; 0
        )

    [1] =&#62; Array
        (
            [0] =&#62; language
            [1] =&#62; 10
        )

    [2] =&#62; Array
        (
            [0] =&#62; programming
            [1] =&#62; 19
        )

)</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167613"
></A
><H2
>Notas</H2
><DIV
CLASS="tip"
><BLOCKQUOTE
CLASS="tip"
><P
><B
>Dica: </B
>
    If you don't need the power of regular expressions, you can choose
    faster (albeit simpler) alternatives like <A
HREF="function.explode.html"
><B
CLASS="function"
>explode()</B
></A
>
    or <A
HREF="function.str-split.html"
><B
CLASS="function"
>str_split()</B
></A
>.
   </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167619"
></A
><H2
>Veja também</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.spliti.html"
><B
CLASS="function"
>spliti()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.split.html"
><B
CLASS="function"
>split()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.implode.html"
><B
CLASS="function"
>implode()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.preg-match.html"
><B
CLASS="function"
>preg_match()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.preg-match-all.html"
><B
CLASS="function"
>preg_match_all()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.preg-replace.html"
><B
CLASS="function"
>preg_replace()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.preg-replace.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="ref.pdf.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>preg_replace</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.pcre.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>PDF Funções</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>