Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 4 1234 LastLast
Results 1 to 10 of 32
  1. #1
    Join Date
    May 2005
    Location
    /etc/passwd
    Posts
    19,110
    Tokens
    1,139

    Latest Awards:

    Default How would I explode this in PHP? :S

    Hey,

    I have some log files where I need to explode the lines into seperate cells in a table, Dan told me to use PHP explode(), which is fine, I'd just use a space as the delimiter, but towards the end of the line I get information that has spaces in I don't want to explode.

    Example line:
    Code:
    2010.5.28 15:08:28 - 10.0.0.13 http://en.wikipedia.org/w/opensearch_desc.php *EXCEPTION* Exception site match. GET 884 0  1 200 - room4-1.domain.example  -
    (Ignore the hyphens, that's information Dansguardian hasn't been able to log).

    As you can see, it's fine until I get to the "Exception site match." area.

    Help please!
    Last edited by Recursion; 01-06-2010 at 04:35 PM.
    Quote Originally Posted by Chippiewill View Post
    e-rebel forum moderator
    :8

  2. #2
    Join Date
    Apr 2010
    Location
    Newcastle
    Posts
    655
    Tokens
    50

    Default

    Which parts of the example do you want separated?

  3. #3
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    array explode ( string $delimiter , string $string [, int $limit ] )

    Limit, see? Use space as the delimiter, limit to as far as you want to go.
    we're smiling but we're close to tears, even after all these years

  4. #4
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Here ya go
    http://habbcrazy.net/jack/thing.php

    Source:
    PHP Code:
    <?php

        $string 
    "2010.5.28 15:08:28 - 10.0.0.13 http://en.wikipedia.org/w/opensearch_desc.php *EXCEPTION* Exception site match. GET 884 0  1 200 - room4-1.domain.example  -";
        
        
    preg_match"/([0-9]{4}.[0-9]{1,2}.[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) - ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}) (.*?) \*EXCEPTION\* Exception site match. (.*?) - (.*?) -/"$string$matches );
        echo 
    "<p>";
        
    print_r$matches );
        echo 
    "</p>";
        
        echo 
    "<strong>Date/Time</strong>: {$matches['1']}<br />";
        echo 
    "<strong>IP</strong>: {$matches['2']}<br />";
        echo 
    "<strong>URL</strong>: {$matches['3']}<br />";
        echo 
    "<strong>GET</strong>: {$matches['4']}<br />";
        echo 
    "<strong>URL 2</strong>: {$matches['5']}<br />";

    ?>
    I gave in with the validation at the end LOL
    Last edited by Moh; 03-06-2010 at 06:08 AM.

  5. #5
    Join Date
    Nov 2005
    Posts
    4,486
    Tokens
    921

    Latest Awards:

    Default

    Nice for doing that ^^ +REP
    "RETIRED" FROM HABBO(X)

    :¬:

    TOMSPIT / COWLY05


  6. #6
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    Quote Originally Posted by Jack120 View Post
    Here ya go
    http://habbcrazy.net/jack/thing.php

    Source:
    PHP Code:
    <?php

        $string 
    "2010.5.28 15:08:28 - 10.0.0.13 http://en.wikipedia.org/w/opensearch_desc.php *EXCEPTION* Exception site match. GET 884 0  1 200 - room4-1.domain.example  -";
        
        
    preg_match"/([0-9]{4}.[0-9]{1,2}.[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) - ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}) (.*?) \*EXCEPTION\* Exception site match. (.*?) - (.*?) -/"$string$matches );
        echo 
    "<p>";
        
    print_r$matches );
        echo 
    "</p>";
        
        echo 
    "<strong>Date/Time</strong>: {$matches['1']}<br />";
        echo 
    "<strong>IP</strong>: {$matches['2']}<br />";
        echo 
    "<strong>URL</strong>: {$matches['3']}<br />";
        echo 
    "<strong>GET</strong>: {$matches['4']}<br />";
        echo 
    "<strong>URL 2</strong>: {$matches['5']}<br />";

    ?>
    I gave in with the validation at the end LOL
    Bit OTT lol.
    we're smiling but we're close to tears, even after all these years

  7. #7
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by MattFr View Post
    Bit OTT lol.
    It's only a preg_match with regular expressions

    Use them all the time

  8. #8
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    Quote Originally Posted by Jack120 View Post
    It's only a preg_match with regular expressions

    Use them all the time
    I know exactly what it is only

    Meh, each to their own.
    we're smiling but we're close to tears, even after all these years

  9. #9
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    "Bit OTT lol."

    Yes, let's all moan at someone for using common sense to create a method that isn't bodging it with an explode.

  10. #10
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    Quote Originally Posted by Source View Post
    "Bit OTT lol."

    Yes, let's all moan at someone for using common sense to create a method that isn't bodging it with an explode.
    I wasn't moaning. A log viewer isn't something that needs to be efficient though, I think practically for the application; there's no point doing the regex for something that isn't important. See see?
    we're smiling but we're close to tears, even after all these years

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •