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. 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 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. 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 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 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
Archived
This topic is now archived and is closed to further replies.