RE: [PHP] breaking a string into chunks

From: Date: Fri, 19 Sep 2003 09:45:26 +0000
Subject: RE: [PHP] breaking a string into chunks
Groups: php.general 
Request: Send a blank email to php-general+get-163117@lists.php.net to get a copy of this message
Make your own function, for example: function transformDate($format,$str) { $d = Array(); for($i=0;$i<strlen($str);$i+=2) { $d[]=substr($str,$i,2); } return date($format,mktime($d[4],$d[5],$d[6],$d[2],$d[3],"$d[0]$d[1]")); } print transformDate("Y-m-d H:i:s","20030917181909"); So, you can change to any format with the first arg. of the function. Javier Tacon Iglesias. -----Mensaje original----- De: David T-G [mailto:davidtg-php@justpickone.org] Enviado el: viernes, 19 de septiembre de 2003 11:20 Para: PHP General list Asunto: [PHP] breaking a string into chunks Importancia: Baja Hi, all -- Now it's my turn to ask a simple question, or one that sure sounds like it should be... I have a 14-char date string like "20030917181909" and I need to break it into its component parts for a more readable "2003-09-17 18:19:09" view. How can I do that? Do I really need to call substr half a dozen times?(!?) I tried unpack() but all I ended up getting was an array with one entry (sometimes with a very strange-looking key). TIA & HAND :-D -- David T-G * There is too much animal courage in (play) davidtg@justpickone.org * society and not sufficient moral courage. (work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

« previous php.general (#163117) next »