Re: Clean break.
| From: | Ollisso | Date: | Fri, 31 Jul 2009 21:59:32 +0000 |
| Subject: | Re: Clean break. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296151@lists.php.net to get a copy of this message | ||
On Sat, 01 Aug 2009 00:22:21 +0300, Paul Halliday <paul.halliday@gmail.com> wrote:
Whats the cleanest (I have a really ugly) way to break this: [21/Jul/2009:00:00:47 -0300] into: date=21/jul/2009 time=00:00:47 ...Why not just use regexp ? For example: $string = "long text.. multiply lines... [21/Jul/2009:00:00:47 -0300] [ 1/Jul/2009:00:00:47 -0300] [22/Jul/2009:00:00:47 -0300]"; preg_match_all('#\[([ 0-9a-zA-Z/]+):([0-9:]+) [^]]+\]#',$string,$matches,PREG_SET_ORDER); print_r($matches); Output: Array (
[0] => Array
(
[0] => [21/Jul/2009:00:00:47 -0300]
[1] => 21/Jul/2009
[2] => 00:00:47
)
[1] => Array
(
[0] => [ 1/Jul/2009:00:00:47 -0300]
[1] => 1/Jul/2009
[2] => 00:00:47
)
[2] => Array
(
[0] => [22/Jul/2009:00:00:47 -0300]
[1] => 22/Jul/2009
[2] => 00:00:47
)
)
--