note 30430 deleted from function.preg-split by tularis
| From: | tularis@php.net | Date: | Thu, 03 May 2007 22:29:21 +0000 |
| Subject: | note 30430 deleted from function.preg-split by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126187@lists.php.net to get a copy of this message | ||
Note Submitter: redph0enix at hotmail dot com
----
preg_split is very useful for splitting up the http common log. Sample:
<?php
$line = '10.0.0.2 - - [17/Mar/2003:18:03:08 +1100] "GET /images/org_background.gif
HTTP/1.0" 200 2321 "http://10.0.0.3/login.php" "Mozilla/5.0
Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021203"';
$elements = preg_split('/^(\S+) (\S+) (\S+) \[([^\]]+)\] "([^"]+)" (\S+) (\S+)
"([^"]+)" "([^"]+)"/', $line,-1,PREG_SPLIT_DELIM_CAPTURE |
PREG_SPLIT_NO_EMPTY);
print_r($elements);
?>
Results:
Array
(
[0] => 10.0.0.2
[1] => -
[2] => -
[3] => 17/Mar/2003:18:03:08 +1100
[4] => GET /images/org_background.gif HTTP/1.0
[5] => 200
[6] => 2321
[7] => http://10.0.0.3/login.php
[8] => Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021203
)