tags:

views:

96

answers:

3

I have the following statement which worked fine before PHP 5.3:

list($year, $month, $day, $hour, $min, $sec) = split( '[: -]', $post_timestamp );

After upgrading to PHP 5.3, I get the Deprecated warning of the title.

I am trying to parse a string with format like:

2010-08-10 23:07:58

into its component parts.

+10  A: 

I think you want preg_split.

list($year, $month, $day, $hour, $min, $sec) = preg_split('/[: -]/', $post_timestamp);
Brandon Horsley
+1  A: 
$dateTime = new DateTime('2010-08-10 23:07:58');

$year = $dateTime->format('Y');
$month = $dateTime->format('m');

You get the drill... Depending, on what you're going to do with it, using DateTime object might be more convenient than using six separate variables.

Mchl
+4  A: 
var_dump(strptime($post_timestamp, '%Y-%m-%d %H:%M:%S'));
zerkms
+1 I posted preg_split as an answer to the replacement for split, but I would have to agree that if you are parsing a timestamp, you should use functions designed for that with proper handling, etc.
Brandon Horsley
@Brandon Horsley: the only weird thing of this solution is that year is not absolute, but the years since 1900 :-S so post-processing is needed :-(
zerkms