<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry id="function.str-split"> <refnamediv> <refname>str_split</refname> <refpurpose> Convert a string to an array </refpurpose> </refnamediv> <refsect1> <title>Description</title> <methodsynopsis> <type>array</type><methodname>str_split</methodname> <methodparam><type>string</type><parameter>string</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>split_length</parameter></methodparam> </methodsynopsis> <para> Converts a string to an array. If the optional <parameter>split_length</parameter> parameter is specified, the returned array will be broken down into chunks with each being <parameter>split_length</parameter> in length, otherwise each chunk will be one character in length. </para> <para> &false; is returned if <parameter>split_length</parameter> is less than 1. If the <parameter>split_length</parameter> length exceeds the length of <parameter>string</parameter>, the entire string is returned as the first (and only) array element. </para> <para> <example> <title>Example uses of <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); /* Output may look like: 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 ) */ ?> ]]> </programlisting> </example> </para> <para> <example> <title>Examples related to <function>str_split</function></title> <programlisting role="php"> <![CDATA[ <?php $str = "Hello Friend"; print $str{0}; // H print $str{8}; // i // Creates: array('H','e','l','l','o',' ','F','r','i','e','n','d') $arr1 = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY); ?> ]]> </programlisting> </example> </para> <para> See also <function>preg_split</function>, <function>split</function>, <function>count_chars</function>, <function>str_word_count</function>, and <link linkend="control-structures.for">for</link>. </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:"../../../../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 -->