Yammyguy Posted April 16, 2009 Share Posted April 16, 2009 I have an array value 090413 which is year, month, day. I've tried: $date = 090413; list($year, $monthday) = str_split($date, 2); list($month, $day) = str_split($monthday, 2); echo"$year <br />$month <br />$day<br />"; This sort of works, however the $day variable has no value. anyone know of a more efficient way of splitting this into 3 parts of two a little more directly? Thanks very much in advance! C. Quote Link to comment https://forums.phpfreaks.com/topic/154292-solved-splitting-6-digit-number-into-3-groups-of-two/ Share on other sites More sharing options...
kenrbnsn Posted April 16, 2009 Share Posted April 16, 2009 Try: <?php $date = '090413'; $yr = substr($date,0,2); $mon = substr($date,2,2); $day = substr($date,4,2); echo $yr . '<br />' . $mon . '<br />' . $day . "<br />"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/154292-solved-splitting-6-digit-number-into-3-groups-of-two/#findComment-811161 Share on other sites More sharing options...
Yammyguy Posted April 16, 2009 Author Share Posted April 16, 2009 Awesome! That works perfectly!!! Thank you very much! Chris. Quote Link to comment https://forums.phpfreaks.com/topic/154292-solved-splitting-6-digit-number-into-3-groups-of-two/#findComment-811163 Share on other sites More sharing options...
.josh Posted April 16, 2009 Share Posted April 16, 2009 if you're using php5 you can use str_split Quote Link to comment https://forums.phpfreaks.com/topic/154292-solved-splitting-6-digit-number-into-3-groups-of-two/#findComment-811166 Share on other sites More sharing options...
kenrbnsn Posted April 16, 2009 Share Posted April 16, 2009 Here it is with str_split <?php $date = '090413'; list($yr,$mon,$day) = str_split($date,2); echo $yr . '<br />' . $mon . '<br />' . $day . "<br />"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/154292-solved-splitting-6-digit-number-into-3-groups-of-two/#findComment-811174 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.