[PHP] splitting string into array

2004-09-29 Thread blackwater dev
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!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] splitting string into array

2004-09-29 Thread raditha dissanayake
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?
 

split()
chunk_split()
substr()
preg_split()
Thanks!
 


--
Raditha Dissanayake.

http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 128 KB | with progress bar.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] splitting string into array

2004-09-29 Thread Chris Dowell
In PHP4
$array = explode(';', chunk_split(A12B05C45D34, 3, ';'));
In PHP4
$array = str_split(A12B05C45D34, 3);
RTFM
Cheers
Chris
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!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] splitting string into array

2004-09-29 Thread Marek Kilimajer
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!
$chunks = preg_split('/(.{3})/', $str, -1, PREG_SPLIT_NO_EMPTY | 
PREG_SPLIT_DELIM_CAPTURE);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] splitting string into array

2004-09-29 Thread Martin Holm
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);
?
||
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] splitting string into array

2004-09-29 Thread Gareth Williams
Try something like this:
$string = 'A12B05C45D34';
$string = chunk_split($string, 3, ':');
//Should give you 'A12:B05:C45:D34';
$array = explode(:,$string);
Cheers,
Gareth
On 29 Sep 2004, at 15:40, 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!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] splitting string into array

2004-09-29 Thread Matt M.
 Example,
 A12B05C45D34
 
 I need to split this into chunks of three A12,B05,C45..etc?

not sure if your string will always be the same patter but this might work

$string = 'A12B05C45D34';

$array = preg_split ( '/([a-zA-Z]\d{2})/', $string,
-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
print_r($array);

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] splitting string into array

2004-09-29 Thread blackwater dev
Thanks all!


On Wed, 29 Sep 2004 14:55:58 +0100, Chris Dowell [EMAIL PROTECTED] wrote:
 In PHP4
 
 $array = explode(';', chunk_split(A12B05C45D34, 3, ';'));
 
 In PHP4
 
 $array = str_split(A12B05C45D34, 3);
 
 RTFM
 
 Cheers
 
 Chris
 
 
 
 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!
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php