Re: Clean break.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 01 Aug 2009 00:22:21 +0300, Paul Halliday <paul.halliday@xxxxxxxxx> 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
        )

)


--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux