Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Quick RegExp Question

    Hello all,

    I'm currently getting information from my apache logs to show information on hits and other information. using the following:

    strstr($strLogFile[$i],"Oct") ? $strOctHits++ : $strOctHits = $strOctHits;

    That works really well, however now for some other information I'll need to see if two values are present in $strLogFile[$i] I've looked through the manual on RegExp and found little useful information and since I've never used RegExp before I was wondering if someone had a good example of looking for two bits of data on one line? thanks!

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if(preg_match("/.(value1).(value2)./is")){

    }

    should work i think, but it really depends what you are doing.... could you be any more specific?

  • #3
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    More Specific? - Sure, no problem.

    Lets say $strLogFile[0] is :

    195.92.67.66 - - [03/Oct/2003:07:41:53 +0100] "GET /favicon.ico HTTP/1.1" 404 - "-" "Mozilla/5.0 (compatible; Konqueror/3.1; Linux)"

    I;d want to count every " 404 " in the month of October. The code I mentioned in my first post goes through counting up the hits per month (counting up the ammount of times "Oct" comes up. However, now I need to count the ammount of times " 404 " comes up when the month is October ;P

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $strOct404 = preg_match("/.*Oct.*404.*/is", $strLogFile[$i]) ? $strOct404++ : $strOct404;


    you could try that

  • #5
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, but alas thats returning a 0.

    $strOct404 = preg_match("/.*Oct.*404.*/is", $strLogFile[$i]) ? $strOct404++ : $strOct404; if ($strOct404 == "") { $strOct404 = "0"; }

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have been tricked by the way how post-increment ($var++) works. The value is incremented after the value has been returned, so you always assign 0 to $strOct404 on each iteration step. Using pre-increment instead increments first and then returns the value. Try if this works for you:

    $strOct404 = preg_match("/.*Oct.*404.*/is", $strLogFile[$i]) ? ++$strOct404 : $strOct404;

    BTW: Why is the variable called 'strOct404'? I suppose that you use hungarian notation, but then... the variable is an integer? Eh?
    De gustibus non est disputandum.

  • #7
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks to the both of you!!!


  •  

    Posting Permissions

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