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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
*    --- Now supporting PHP5 ---
****************************************/

Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux