pioneerx01 Posted August 23, 2011 Share Posted August 23, 2011 I am trying to separate a values into independent components. In my case it is a time stamp such as 08-22-2011 18:02. I have seen the code before but I can not remember where or what it is called. Basically I define that this string should be exploded with values being between -, -, ,: and reminders are $day, $month, $year, $hour, $minute. If you can point me in the correct direction I would appreciate it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/245524-what-is-the-script-to-take-string-appart/ Share on other sites More sharing options...
Pikachu2000 Posted August 23, 2011 Share Posted August 23, 2011 What is the purpose of doing that? Depending on what your end goal is, there may be a better way to handle this. Quote Link to comment https://forums.phpfreaks.com/topic/245524-what-is-the-script-to-take-string-appart/#findComment-1261059 Share on other sites More sharing options...
codefossa Posted August 23, 2011 Share Posted August 23, 2011 $string = '1, 2, 3, 4, 5'; $array = explode(', ', $string); Quote Link to comment https://forums.phpfreaks.com/topic/245524-what-is-the-script-to-take-string-appart/#findComment-1261060 Share on other sites More sharing options...
jcbones Posted August 24, 2011 Share Posted August 24, 2011 Two ways off the top of my head: <?php //using date function. (not recommended, cause I think it is dirty). $timestamp = '2011-08-22 18:02:00'; //notice the timestamp change from the format provided. $time = strtotime($timestamp); $month = date('m',$time); $day = date('d',$time); $year = date('Y',$time); $hour = date('H',$time); $minute = date('i',$time); $second = date('s',$time); echo 'Month: ' . $month . '<br />Day: ' . $day . '<br />Year: ' . $year . '<br />Hour: ' . $hour . '<br />Minute: ' . $minute . '<br />Second: ' . $second . '<hr />'; //using explode $timestamp = '08-22-2011 18:02:00'; $split = explode(' ',$timestamp); list($month, $day, $year) = explode('-',$split[0]); list($hour, $minute, $second) = explode(':',$split[1]); echo 'Month: ' . $month . '<br />Day: ' . $day . '<br />Year: ' . $year . '<br />Hour: ' . $hour . '<br />Minute: ' . $minute . '<br />Second: ' . $second; Quote Link to comment https://forums.phpfreaks.com/topic/245524-what-is-the-script-to-take-string-appart/#findComment-1261152 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.