Re: Splitting 12345 -> 1,2,3,4,5

From: Date: Thu, 16 Sep 2004 14:48:03 +0000
Subject: Re: Splitting 12345 -> 1,2,3,4,5
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-196864@lists.php.net to get a copy of this message
Martin Holm wrote:
Michael Mao wrote:
Thanks John. Found what I'm looking for: Function str_split()
to make it php4 compatible you can use this function: |<?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);
here, you can also use: $arr[] = $str{$i}; and use $i++ instead of $i += $size if you don't need strings larger than 1 character.
     }
     return $arr;
} } ?> works in about the same way as the function in php5. |


« previous php.general (#196864) next »