Note that there are some explanatory texts on larger screens.

plurals
  1. POParse Apache log in PHP using preg_match
    primarykey
    data
    text
    <p>I need to save data in a table (for reporting, stats etc...) so a user can search by time, user agent etc. I have a script that runs every day that reads the Apache Log and then insert it in the database. </p> <p>Log format:</p> <pre><code>10.1.1.150 - - [29/September/2011:14:21:49 -0400] "GET /info/ HTTP/1.1" 200 9955 "http://www.domain.com/download/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1" </code></pre> <p>My regex:</p> <pre><code>preg_match('/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.*?) (\S+)\" (\S+) (\S+) (\".*?\") (\".*?\")$/',$log, $matches); </code></pre> <p>Now when I print: </p> <pre><code>print_r($matches); Array ( [0] =&gt; 10.1.1.150 - - [29/September/2011:14:21:49 -0400] "GET /info/ HTTP/1.1" 200 9955 "http://www.domain.com/download/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1" [1] =&gt; 10.1.1.150 [2] =&gt; - [3] =&gt; - [4] =&gt; 29/September/2011 [5] =&gt; 14:21:49 [6] =&gt; -0400 [7] =&gt; GET [8] =&gt; /info/ [9] =&gt; HTTP/1.1 [10] =&gt; 200 [11] =&gt; 9955 [12] =&gt; "http://www.domain.com/download/" [13] =&gt; "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1" ) </code></pre> <p>I get: <code>"http://www.domain.com/download/"</code> and same for user agent. How can I get rid of these <code>"</code> in the regex? Bonus (Is there any quick way to insert the date/time easily)?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload