Re: splitting string into array

From: Date: Wed, 29 Sep 2004 13:58:53 +0000
Subject: Re: splitting string into array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-198188@lists.php.net to get a copy of this message
blackwater dev wrote:
How can I take a string and create an array? Example, A12B05C45D34 I need to split this into chunks of three A12,B05,C45..etc? Thanks! |
use str_split() if you dont have php5, you can use the following code: | <?php if (!function_exists('str_split')) {
       function str_split ($str, $size = 1) {
               $arr = array();
               for ($i = 0 ; $i < strlen($str) ; $i += $size) {
                       $arr[] = substr($str,$i,$size);
               }
               return $arr;
       }
} $array = str_split('A12B05C45D34',3) print_r($array); ?> ||

« previous php.general (#198188) next »