Re: help me split chars w/o spaces by 2... like: 2004

From: Date: Thu, 09 Dec 2004 02:21:52 +0000
Subject: Re: help me split chars w/o spaces by 2... like: 2004
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-203784@lists.php.net to get a copy of this message
On Thu, 2004-12-09 at 09:55 +0800, Louie Miranda wrote: > Help me split chars w/o spaces by 2... like: 2004 > How can i make it? > > first: 20 > second: 04 > > Im working on this.. > > ##### begin code > $year_split = date("Y"); > $chars = preg_split('//', $year_split, -1, PREG_SPLIT_NO_EMPTY); > ##### end code > > But it splits the whole "2004" string.. > > Array > ( > [0] => 2 > [1] => 0 > [2] => 0 > [3] => 4 > ) > > First of all, what sort of code are you building that needs to split the year by 2 sets of 2 digits? Second, you can do this like so: $foo = date("Y"); $bar = array(); $bar[] = substr($foo,0,2); $bar[] = substr($foo,2,2); print_r($bar); > Array > ( > [0] => 20 > [1] => 04 > ) -Robby -- /*************************************** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | robby@planetargon.com * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting & Development * --- Now supporting PHP5 --- ****************************************/

Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
« previous php.general (#203784) next »