<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >split</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Regular Expression Functions (POSIX Extended)" HREF="ref.regex.html"><LINK REL="PREVIOUS" TITLE="eregi" HREF="function.eregi.html"><LINK REL="NEXT" TITLE="spliti" HREF="function.spliti.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></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 PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.eregi.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.spliti.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.split" ></A >split</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN100651" ></A ><P > (PHP 3, PHP 4 , PHP 5)</P >split -- split string into array by regular expression</DIV ><DIV CLASS="refsect1" ><A NAME="AEN100654" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >split</B > ( string pattern, string string [, int limit])<BR ></BR ><DIV CLASS="tip" ><BLOCKQUOTE CLASS="tip" ><P ><B >Indicaþie: </B > <A HREF="function.preg-split.html" ><B CLASS="function" >preg_split()</B ></A >, which uses a Perl-compatible regular expression syntax, is often a faster alternative to <B CLASS="function" >split()</B >. If you don't require the power of regular expressions, it is faster to use <A HREF="function.explode.html" ><B CLASS="function" >explode()</B ></A >, which doesn't incur the overhead of the regular expression engine. </P ></BLOCKQUOTE ></DIV ><P > Returns an array of strings, each of which is a substring of <VAR CLASS="parameter" >string</VAR > formed by splitting it on boundaries formed by the case-sensitive regular expression <VAR CLASS="parameter" >pattern</VAR >. If <VAR CLASS="parameter" >limit</VAR > is set, the returned array will contain a maximum of <VAR CLASS="parameter" >limit</VAR > elements with the last element containing the whole rest of <VAR CLASS="parameter" >string</VAR >. If an error occurs, <B CLASS="function" >split()</B > returns <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ><P > To split off the first four fields from a line from <TT CLASS="filename" >/etc/passwd</TT >: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN100684" ></A ><P ><B >Exemplu 1. <B CLASS="function" >split()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">list(</font><font color="#0000BB">$user</font><font color="#007700">, </font><font color="#0000BB">$pass</font><font color="#007700">, </font><font color="#0000BB">$uid</font><font color="#007700">, </font><font color="#0000BB">$gid</font><font color="#007700">, </font><font color="#0000BB">$extra</font><font color="#007700">) =<br /> </font><font color="#0000BB">split</font><font color="#007700">(</font><font color="#DD0000">":"</font><font color="#007700">, </font><font color="#0000BB">$passwd_line</font><font color="#007700">, </font><font color="#0000BB">5</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > If there are <VAR CLASS="replaceable" >n</VAR > occurrences of <VAR CLASS="parameter" >pattern</VAR >, the returned array will contain <VAR CLASS="literal" ><VAR CLASS="replaceable" >n</VAR >+1</VAR > items. For example, if there is no occurrence of <VAR CLASS="parameter" >pattern</VAR >, an array with only one element will be returned. Of course, this is also true if <VAR CLASS="parameter" >string</VAR > is empty. </P ><P > To parse a date which may be delimited with slashes, dots, or hyphens: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN100697" ></A ><P ><B >Exemplu 2. <B CLASS="function" >split()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">// Delimiters may be slash, dot, or hyphen<br /></font><font color="#0000BB">$date </font><font color="#007700">= </font><font color="#DD0000">"04/30/1973"</font><font color="#007700">;<br />list(</font><font color="#0000BB">$month</font><font color="#007700">, </font><font color="#0000BB">$day</font><font color="#007700">, </font><font color="#0000BB">$year</font><font color="#007700">) = </font><font color="#0000BB">split</font><font color="#007700">(</font><font color="#DD0000">'[/.-]'</font><font color="#007700">, </font><font color="#0000BB">$date</font><font color="#007700">);<br />echo </font><font color="#DD0000">"Month: $month; Day: $day; Year: $year<br /></font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > For users looking for a way to emulate Perl's <B CLASS="command" >@chars = split('', $str)</B > behaviour, please see the examples for <A HREF="function.preg-split.html" ><B CLASS="function" >preg_split()</B ></A >. </P ><P > Please note that <VAR CLASS="parameter" >pattern</VAR > is a regular expression. If you want to split on any of the characters which are considered special by regular expressions, you'll need to escape them first. If you think <B CLASS="function" >split()</B > (or any other regex function, for that matter) is doing something weird, please read the file <TT CLASS="filename" >regex.7</TT >, included in the <TT CLASS="filename" >regex/</TT > subdirectory of the PHP distribution. It's in manpage format, so you'll want to do something along the lines of <B CLASS="command" >man /usr/local/src/regex/regex.7</B > in order to read it. </P ><P > See also: <A HREF="function.preg-split.html" ><B CLASS="function" >preg_split()</B ></A >, <A HREF="function.spliti.html" ><B CLASS="function" >spliti()</B ></A >, <A HREF="function.explode.html" ><B CLASS="function" >explode()</B ></A >, <A HREF="function.implode.html" ><B CLASS="function" >implode()</B ></A >, <A HREF="function.chunk-split.html" ><B CLASS="function" >chunk_split()</B ></A >, and <A HREF="function.wordwrap.html" ><B CLASS="function" >wordwrap()</B ></A >. </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.eregi.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.spliti.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >eregi</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.regex.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >spliti</TD ></TR ></TABLE ></DIV ></BODY ></HTML >