Re: breaking a string into chunks

From: Date: Fri, 19 Sep 2003 10:01:53 +0000
Subject: Re: breaking a string into chunks
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-163113@lists.php.net to get a copy of this message
On Friday 19 Sep 2003 10:20, David T-G wrote: > 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 In perl I'd do something like: $time =~ m/(\d){4}(\d){2}(\d){2}(\d){2}(\d){2}(\d){2}/; $ntime = "$1-$2-$3 $4:$5:$6"; I think php can do that with preg_match, using an array to hold the matches. As the other poster said, if this is mysql, let mysql do the work for you :)

« previous php.general (#163113) next »