note 30430 added to function.preg-split

From: Date: Tue, 18 Mar 2003 10:52:15 +0000
Subject: note 30430 added to function.preg-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-45445@lists.php.net to get a copy of this message
preg_split is very useful for splitting up the http common log. Sample: $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 ) -- http://www.php.net/manual/en/function.preg-split.php http://master.php.net/manage/user-notes.php?action=edit+30430 http://master.php.net/manage/user-notes.php?action=delete+30430 http://master.php.net/manage/user-notes.php?action=reject+30430

« previous php.notes (#45445) next »