Re: Re: Clean break.

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

 



On Sat, 01 Aug 2009 01:37:56 +0300, Paul Halliday <paul.halliday@xxxxxxxxx> wrote:

Actually, I don't think that regexp's are very slow :)

But I haven't tested them from that perspective.

You should just benchamrk different approaches :)
btw, not sure that substr will help you a lot:

first you have to get a begining of the time, block, then you have to find next X chars.

Btw, you can also do it with a quite simple regexp:
preg_match_all('#\[(.{20})#', ..
(where 20 is amount of characters you want to extract.)
or:
preg_match_all('#\[(.{8})(.{12})#', ..
(where 8 is first part of date, and 12 is second part of date.)

But then you will have to parse this string, to convert it to time, which could take time.

You should just benchmark different approaches, and check which is fastest.

PS: numbers 20,8, 12 are random, just put whtever you need :)
PPS: haven't tested regexps, just check the idea)




I was trying to stay away from regex as much as possible due to the
overhead? I might be wrong here.

This script will be parsing a lot of requests/sec. Thousands, maybe
more, which it also needs to toss into a DB. I want to try and keep it
as fast as possible. This is tricky when you don't know what you are
doing :). My coding is limited to hammering away at the search box on
php.net until I get a push in the right direction. It's just a hack
from there.

Using phpster's substr suggestion has already sped this up considerably.


2009/7/31 Ollisso <ollisso@xxxxxxxxxx>:
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










--
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